0

下面的代码将backgroundColorcommit.

[CATransaction begin];
self.view.backgroundColor = [UIColor redColor];
[CATransaction commit];

sleep(5);

但是使用嵌套显式CATransactions,仅在最外层事务提交时才更新屏幕。

[CATransaction begin];
[CATransaction begin];
self.view.backgroundColor = [UIColor redColor];
[CATransaction commit];
sleep(5);
[CATransaction commit];

所以这很奇怪,因为我们知道 runloop 会在每个循环中创建一个最外层的隐式事务。为什么在提交implicit transaction时这不被视为最外层事务?explicit transaction

4

1 回答 1

2

始终存在隐式事务。也可以有显式事务。在所有代码完成运行之前,隐式事务不会提交。如果您有一个显式事务 ( beginand commit),那么它会在commit遇到时提交。

嵌套显式事务的目的只是为了让您为动画的不同部分提供不同的参数(例如持续时间);实际提交直到最外层才会发生commit。阅读文档

只有在您提交最外层事务的更改后,Core Animation 才会开始相关的动画

于 2016-09-05T03:15:27.780 回答