UITableViewCell animate height issue in iOS 10

后端 未结 7 1851
余生分开走
余生分开走 2020-12-13 14:23

My UITableViewCell will animate it\'s height when recognizing a tap. In iOS 9 and below this animation is smooth and works without issues. In iOS 10 beta there\

7条回答
  •  隐瞒了意图╮
    2020-12-13 15:19

    Can't comment because of reputation but sam's solution worked for me on IOS 10.

     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        EWGDownloadTableViewCell *cell = (EWGDownloadTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    
        if (self.expandedRow == indexPath.row) {
            self.expandedRow = -1;
            [UIView animateWithDuration:0.3 animations:^{
                cell.constraintToAnimate.constant = 51;
                [tableView beginUpdates];
                [tableView endUpdates];
                [cell layoutIfNeeded];
            } completion:nil];
        } else {
            self.expandedRow = indexPath.row;
            [UIView animateWithDuration:0.3 animations:^{
                cell.constraintToAnimate.constant = 100;
                [tableView beginUpdates];
                [tableView endUpdates];
                [cell layoutIfNeeded];
            } completion:nil];
        } }
    

    where constraintToAnimate is a height constraint on a subview added to the cells contentView.

提交回复
热议问题