implicit (adj.) – capable of being understood from something else though unexpressed – Merriam Webster
- Good for: when you don’t want to write a lot of code and the default timing works in your use case, for example: changing a layer’s opacity from 1.0 to 0.0
- Implicit animations use default timing and default animation properties Updates the layer object’s data value in the layer tree
Just update properties of your layer object. Note: When changing layer objects, the changes are reflected immediately by those layer objects – however, the visual appearance of those objects does not change immediately. Instead, Core Animation uses your changes as a trigger to create and schedule one or more implicit animations for execution.
redSquareLayer.opacity = 0.0
- Good for: when you want more customized animations
- Does not update the data in the layer tree; Explicit animations only produce animations
- It is recommended to always assign the fromValue of the animation object in an explicit animation
- At the end of the animation, Core Animation removes the animation object from the layer and redraws the layer using its current data values
- Create the animation object
- Set the fromValue, toValue, duration, and/or other properties
- Add the animation to the layer you want to animate
- Set the actual data value in the layer to the final value
let opacityAnimation = CABasicAnimation(keyPath: "opacity") opacityAnimation.fromValue = 1.0 opacityAnimation.toValue = 0.0 opacityAnimation.duration = 3.0 redSquareLayer.add(opacityAnimation, forKey: "opacity") redSquareLayer.opacity = 0.0 // Set the actual data value in the layer to the final value
- If you change multiple properties and/or add multiple animation objects to a layer, all those property changes animate at the same time.
- For example changing a layer’s color and opacity – these properties will animate simultaneously.
- However, you can also set animation objects to start at a specific time – more information here: Customizing the Timing of an Animation(https://web.archive.org/web/20170504083814/https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/TP40004514-CH8-SW2)