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

查看:28
本文介绍了如何检测动画已在 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天全站免登陆