ios - 如何等到 UITableView 内置动画完成?

标签 ios objective-c uitableview

<分区>

 [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
 [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];

在上面的代码中,如何让第二行在第一行的动画完成后执行?

我试过了...

[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
{
    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
    [self.tableView endUpdates];
}
[self.tableView endUpdates];

还有这个……

[self.tableView beginUpdates];
{
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
}
[self.tableView endUpdates];
[self.tableView beginUpdates];
{
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
}

...但无论哪种方式,动画显然是同时发生的(并且在打开慢速动画时非常明显)。

最佳答案

感谢 Iducool 为我指出另一个问题。

这有效...

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
}];

[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];

[CATransaction commit];

我似乎不需要 UITableViewbeginUpdatesendUpdates

关于ios - 如何等到 UITableView 内置动画完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16262327/

相关文章:

ios - NSTimer 与 UITableView

ios - Payu Swift 集成中 PayUCreateRequest 的 createRequest() 函数中的 NSURL 问题

objective-c - RestKit 图片上传

c++ - 将第 3 方 C++ 库添加到 Objective-C 项目中

ios - 如何设置这个自定义 UITableViewCell

ios - TableView索引从rootcontroller到detailcontroller(UINavigationController)

ios - 使用 Restkit 中的 RKObjectManager 在 https 和 http 之间切换的最佳方法是什么?

iphone - NSFetchedResultController 多重限制和排序

ios - 将现有的 Swift 1.2 代码转换为 2.0 后,Xcode 无法识别属性

ios - 在详细信息标题栏中,显示 “Picture X of Y”