Reputation: 745
The code below will update the backgroundColor
immediately after the commit
.
[CATransaction begin];
self.view.backgroundColor = [UIColor redColor];
[CATransaction commit];
sleep(5);
But with nested explicit CATransactions
, screen update only when outer most transaction commit.
[CATransaction begin];
[CATransaction begin];
self.view.backgroundColor = [UIColor redColor];
[CATransaction commit];
sleep(5);
[CATransaction commit];
So this make it very strange, because we know runloop will create a outer most implicit transaction each loop. Why this implicit transaction
is not viewed as outer most transaction when a explicit transaction
commit?
Upvotes: 0
Views: 938
Reputation: 536027
There is an implicit transaction always. There can also be an explicit transaction. The implicit transaction does not commit until all your code has finished running. If you have an explicit transaction (begin
and commit
), then it commits when the commit
is encountered.
The purpose of nested explicit transactions is only to allow you to provide different parameters (e.g. duration) for different parts of the animation; the actual commit does not happen until the outermost commit
. Read the docs:
Only after you commit the changes for the outermost transaction does Core Animation begin the associated animations
Upvotes: 3