在为UITableView设置动画时停止UITableViewCells动画

dra*_*aur 8 uitableview uianimation ios autolayout

我正在为UITableView制作动画.我希望表视图像这样滑动打开:

http://www.youtube.com/watch?v=XIGJLbiRsXE

但是,它打开如下:

http://www.youtube.com/watch?v=UJUX-ILCB_0

注意表格单元格本身是如何制作动画的.我怎么能阻止这种情况发生?

我正在使用autolayout.因此代码如下:

[theView addSubview:theTable];
[theTable reloadData];
[theTable invalidateIntrinsicContentSize];
[UIView animateWithDuration:.33 animations:^{
    [theView layoutIfNeeded];
 }];
Run Code Online (Sandbox Code Playgroud)

其他细节,可能会或可能不重要:

  • 表视图的父级是scrollView

  • 我重写了表视图的intrinsicContentSize以返回表视图中所有单元格的高度,因此表视图不会滚动

  • 我在显示之前更改了表视图的数据源

小智 13

我有类似的问题,并能够使用UIView performWithoutAnimation:方法停止UITableViewCell上的动画.

使用tableView:willDisplayCell:forRowAtIndexPath:UITableViewDelegate方法在显示单元格之前获取对单元格的引用.然后,在performWithoutAnimation:块中,调用layoutIfNeeded单元格对象,使其有机会布置其子视图:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [UIView performWithoutAnimation:^{
        [cell layoutIfNeeded];
    }];
}
Run Code Online (Sandbox Code Playgroud)


Jos*_*ner 1

您是否考虑过对位于表视图上方的不透明子视图进行动画处理?

[theView addSubview:theTable];
[theTable reloadData];

UIView *subview = [[UIView alloc] initWithFrame:theTable.frame];
subview.backgroundColor = [UIColor whiteColor];
[theView addSubview:subview];

[UIView animateWithDuration:0.33 animations:^{
    subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.size.height, subview.frame.size.width, 0.0);
}];
Run Code Online (Sandbox Code Playgroud)