【问题标题】:Disable implicit animation without CATransaction begin&commit在没有 CATransaction begin&commit 的情况下禁用隐式动画
【发布时间】:2014-06-07 16:07:51
【问题描述】:

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

[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?有没有我必须使用它们的案例?

谢谢,阿恩。

【问题讨论】:

    标签: ios objective-c core-animation catransaction


    【解决方案1】:

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

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

    【讨论】:

    • 此外,如果您在系统动画期间禁用当前事务块上的操作,您很可能会“损坏”整个动画,而不是只执行更改而不执行动画。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 2014-03-08
    • 2017-07-16
    • 2016-04-16
    相关资源
    最近更新 更多