gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:06:41 34 4
gpt4 key购买 nike

我正在为 UITableView 制作动画。我希望表格 View 像这样滑动打开:

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

但是,它打开是这样的:

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

注意表格单元格本身是如何动画的。我怎样才能阻止这种情况发生?

我正在使用自动布局。代码是这样的:

[theView addSubview:theTable];
[theTable reloadData];
[theTable invalidateIntrinsicContentSize];
[UIView animateWithDuration:.33 animations:^{
[theView layoutIfNeeded];
}];

其他细节,可能重要也可能不重要:

  • table view 的父级是 scrollView

  • 我已经覆盖了 TableView 的 intrinsicContentSize 以返回 TableView 中所有单元格的高度,因此 TableView 不会滚动

  • 我在显示之前更改 TableView 的数据源

最佳答案

我遇到了类似的问题,并且能够使用 UIView performWithoutAnimation: 方法停止 UITableViewCell 上的动画。

使用 tableView:willDisplayCell:forRowAtIndexPath: UITableViewDelegate 方法在单元格显示之前获取对单元格的引用。然后,在 performWithoutAnimation: block 中,对单元格对象调用 layoutIfNeeded 以使其有机会布局其 subview :

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

关于ios - 在为 UITableView 设置动画时停止 UITableViewCells 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16284818/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com