我如何等待UITableView内置动画完成? [英] How do I wait until a UITableView built-in animation is complete?

查看:77
本文介绍了我如何等待UITableView内置动画完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

In the above code how do I make the second line execute after the animation from the first line has completed?

我试过这个......

I tried this...

[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];
}

...但无论哪种方式动画都在同一时间发生(当慢动画开始时真的很明显)。

...but either way the animations are clearly happening at the same time (and really apparent when slow animations is on).

推荐答案

感谢Iducool指点我另一个问题。

Thank you Iducool for pointing me to the other question.

这有效......

[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];

我似乎不需要 UITableView beginUpdates endUpdates

这篇关于我如何等待UITableView内置动画完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆