Animations provided by Core Animation conform to the CAMediaTiming protocol, meaning that they implement (among many other things) a beginTime variable, with which we can delay the start of an animation.
This allows us to coordinate the timing of separate animations. To demonstrate this, we will do the following:
- We will create a visual row of identical CALayer objects.
- We will then pass identical animations to each of the layers, which differ only in their beginTime property values. We'll do this in a loop in the code.
So first, we need to create the layers.
Add the following method to the ViewController class:
func buildSquareLayers() { for i in 0..<colors.count { let layer = CALayer() layer.bounds = CGRect(x: ...