Ios 设置UITableView动画时,停止UITableViewCells的动画设置
我正在制作UITableView的动画。我希望表格视图以如下方式滑开: 但是,它是这样打开的: 请注意表格单元格本身是如何设置动画的。我怎样才能阻止这种事情发生 我正在使用自动布局。因此,守则是:Ios 设置UITableView动画时,停止UITableViewCells的动画设置,ios,uitableview,autolayout,uianimation,Ios,Uitableview,Autolayout,Uianimation,我正在制作UITableView的动画。我希望表格视图以如下方式滑开: 但是,它是这样打开的: 请注意表格单元格本身是如何设置动画的。我怎样才能阻止这种事情发生 我正在使用自动布局。因此,守则是: [theView addSubview:theTable]; [theTable reloadData]; [theTable invalidateIntrinsicContentSize]; [UIView animateWithDuration:.33 animations:^{ [t
[theView addSubview:theTable];
[theTable reloadData];
[theTable invalidateIntrinsicContentSize];
[UIView animateWithDuration:.33 animations:^{
[theView layoutIfNeeded];
}];
其他可能重要或不重要的细节:
- 表视图的父视图是滚动视图
- 我已经覆盖了表视图的intrinsicContentSize以返回表视图中所有单元格的高度,因此表视图不会滚动
- 我正在更改表视图的数据源,然后再显示它
[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);
}];
在调用动画块内的[View LayoutifNeed]之前,请先尝试布局表格。理想情况下,您可以逐块布局,在0.33秒的时间内,您可以在表格上获得一个滚动条,但目标是使表格单元格布局在动画块之外发生更改。我也遇到了类似的问题,并且能够使用UIView
性能停止UITableViewCell上的动画,而无需动画:
方法
使用tableView:willDisplayCell:forrowatinexpath:
UITableViewDelegate方法在显示单元格之前获取对该单元格的引用。然后,在performwhithoutanimation:
块中,调用单元格对象上的layoutifneed
,使其有机会布局其子视图:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[UIView performWithoutAnimation:^{
[cell layoutIfNeeded];
}];
}
回答这个问题可能太晚了,但在这种情况下,问题通常在于动画块捕获下一次运行循环中计划的所有挂起布局 我使用的解决方案是。我在动画之前(设置或使任何约束无效之前)调用layoutIfNeeded,然后在动画块内部调用layoutIfNeeded 在你的情况下是这样的
[theView addSubview:theTable];
[theTable reloadData];
[theView layoutIfNeeded];
[theTable invalidateIntrinsicContentSize];
[UIView animateWithDuration:.33 animations:^{
[theView layoutIfNeeded];
}];
我认为这在我的例子中不起作用,因为表下面的子视图也需要随着表上下移动。