如何在UITableView beginUpdates / endUpdates上检测到该动画已结束? [英] How to detect that animation has ended on UITableView beginUpdates/endUpdates?

查看:200
本文介绍了如何在UITableView beginUpdates / endUpdates上检测到该动画已结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 beginUpdates / endUpdates 中包含的 insertRowsAtIndexPaths / deleteRowsAtIndexPaths 插入/删除表格单元格。我在调整rowHeight时也使用 beginUpdates / endUpdates 。默认情况下,所有这些操作都是动画的。

I am inserting/deleting table cell using insertRowsAtIndexPaths/deleteRowsAtIndexPaths wrapped in beginUpdates/endUpdates. I am also using beginUpdates/endUpdates when adjusting rowHeight. All these operations are animated by default.

使用 beginUpdates / endUpdates 时,如何检测动画已结束?

How can I detect that animation has ended when using beginUpdates/endUpdates?

推荐答案

这个怎么样?

[CATransaction begin];

[CATransaction setCompletionBlock:^{
    // animation has finished
}];

[tableView beginUpdates];
// do some work
[tableView endUpdates];

[CATransaction commit];

这是有效的,因为tableView动画使用 CALayer 内部动画。也就是说,他们将动画添加到任何打开的 CATransaction 。如果没有打开 CATransaction (正常情况),则会隐式启动一个,这将在当前runloop结束时结束。但是,如果你自己开始,就像在这里完成一样,那么它将使用那个。

This works because the tableView animations use CALayer animations internally. That is, they add the animations to any open CATransaction. If no open CATransaction exists (the normal case), then one is implicitly began, which is ended at the end of the current runloop. But if you begin one yourself, like is done here, then it will use that one.

这篇关于如何在UITableView beginUpdates / endUpdates上检测到该动画已结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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