ios - 在没有 CATransaction begin&commit 的情况下禁用隐式动画

标签 ios objective-c core-animation catransaction

我看到很多人用它来禁用隐式动画:

[CATransaction begin];
[CATransaction setDisableActions:YES];
someLayer.backgroundColor = someCGColor;//no animation
[CATransaction commit];

但是没有 CATransaction begin&commit 它也可以工作:

[CATransaction setDisableActions:YES];
someLayer.backgroundColor = someCGColor;//no animation

像这样它也可以工作:

[CATransaction setDisableActions:YES];
someLayer1.backgroundColor = someCGColor;//no animation
[CATransaction setDisableActions:NO];
someLayer2.backgroundColor = someCGColor2; //have animation

那么问题来了,为什么我需要使用CATransaction begin&commit?在某些情况下我必须使用它们吗?

谢谢,Aunn。

最佳答案

这与 Core Animation 中的事务 block 有关。默认情况下,有一个隐式事务 block 会自动捕获对 CATransaction 的调用。使用 CATransaction begin/commit 创建一个显式事务 block ,允许您将不同的动画特性应用于动画的不同元素。

理论上,如果某些事情需要立即完成而不是在下一次重绘调用时完成,例如添加或删除动画,您可能需要一个显式事务 block 。如果操作不当,例如在执行任何绘制调用之前启动动画,这会导致问题。

关于ios - 在没有 CATransaction begin&commit 的情况下禁用隐式动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24099089/

相关文章:

ios - 对 Segment 使用约束时发生冲突

ios - UITableViewController 类似于 iOS7 日历应用程序的添加事件 TableView Controller

iphone - 如何将属性设为私有(private)?

ios - 链接关键帧动画

ios - CATextLayer 旋转后文本模糊

ios - 为什么要使用委托(delegate)?

ios - swift 语言中的 null/nil

objective-c - 如何防止自定义 UITableViewCells 在取消选择时闪烁白色?

iphone - 像动画一样使用 UIAlertVIew 添加 subview ,具有弹跳效果

ios - 清除绘图的 UIView?