A mechanism for creating implicit animations and combining scene graph changes into atomic updates.
- iOS 8.0+
- macOS 10.8+
- tvOS 9.0+
- watchOS 2.0+
SCNTransaction class methods to control the animation that results from changing animatable properties in the scene graph and to combine sets of changes into nested transactions.
Adding Animation with Automatic Transaction
SceneKit creates a transaction automatically whenever you modify the objects in a scene graph. This transaction groups any additional changes you make from the same thread during the current iteration of that thread’s run loop. When the run loop next iterates, SceneKit automatically commits the transaction, atomically applying all changes made during the transaction to the presentation scene graph (that is, the, version of the scene graph currently being displayed).
Because an automatic transaction has a default duration of zero, any changes it contains appear instantly when SceneKit automatically commits the transaction. By using the setAnimationDuration: method to change the duration, you implicitly animate all changes made to animatable properties during the transaction. You can use implicit animation to add animation to a scene quickly and easily. For example, the code in Listing 1 fades out and moves one node, fades in another, moves and zooms the point of view camera, and focuses a spotlight, all in a single one-second animation.
Creating Advanced Animations with Custom Transactions
You can also use
SCNTransaction class methods to create and manage a hierarchy of your own transactions. By nesting custom transactions, you can group sets of scene graph changes, applying different animation parameters to each group. Use the
begin method to create a custom transaction, nested within the current transaction if one exists. Use the
commit method to end a transaction, applying all scene graph changes made within.