A mechanism for grouping multiple layer-tree operations into atomic updates to the render tree.
- iOS 2.0+
- macOS 10.5+
- Mac Catalyst 13.0+
- tvOS 9.0+
- Core Animation
CATransaction is the Core Animation mechanism for batching multiple layer-tree operations into atomic updates to the render tree. Every modification to a layer tree must be part of a transaction. Nested transactions are supported.
Core Animation supports two types of transactions: implicit transactions and explicit transactions. Implicit transactions are created automatically when the layer tree is modified by a thread without an active transaction and are committed automatically when the thread's runloop next iterates. Explicit transactions occur when the the application sends the
CATransaction class a
begin() message before modifying the layer tree, and a
commit() message afterwards.
CATransaction allows you to override default animation properties that are set for animatable properties. You can customize duration, timing function, whether changes to properties trigger animations, and provide a handler that informs you when all animations from the transaction group are completed.
During a transaction you can temporarily acquire a recursive spin lock for managing property atomicity.
CATransaction supports nested transactions. Listing 1 shows how you can fade out a layer (named
transitioning) over a 2 second duration while scaling it to three times its original size. The scale animation is within a nested transaction with its own duration of 1 second. After the outer transaction completes, a completion block removes
transitioning from its parent layer.