Disable implicit animation without CATransaction begin&commit
Asked Answered
F

1

6

I see many people use this to disable implicit animation:

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

But without CATransaction begin&commit it also works:

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

And like this it also works:

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

So the question is, why I need to use CATransaction begin&commit? Are there any cases that I have to use them?

Thanks , Aunn.

Frederick answered 7/6, 2014 at 16:7 Comment(0)
S
2

This has to do with transaction blocks in Core Animation. By default, there is an implicit transaction block that automatically catches the calls to CATransaction. Using CATransaction begin/commit creates an explicit transaction block that allows you to apply different animation characteristics to different elements of an animation.

Theoretically, you might need an explicit transaction block if something needs to be done immediately and not on the next redraw call, such as adding or removing animations. This cause problems when done incorrectly, such as by starting an animation before any draw calls are being done.

Shults answered 12/6, 2014 at 16:2 Comment(1)
In addition, if you disable actions on the current transaction block during a system animation, you will more than likely "damage" the entire animation, rather than only performing your changes without animation.Stig

© 2022 - 2024 — McMap. All rights reserved.