You create an instance of CABasicAnimation using the inherited init(keyPath:) method, specifying the key path of the property to be animated in the render tree.
For example, you can animate a layer's scalar (i.e. containing a single value) properties such as its opacity. Listing 1 fades in a layer by animating its opacity from 0 to 1.
Non-scalar properties, such as backgroundColor, can also be animated. Core Animation will interpolate between the fromValue color and the toValue color. The animation created in Listing 2 fades a layer's background color from red to blue.
If you want to animate the individual components of a non-scalar property with different values, you pass the values to toValue and fromValue as arrays. The animation created in Listing 3 moves a layer from (0, 0) to (100, 100).
The keyPath can access the individual components of a property. For example, the Listing 4 stretches a layer by animating its transform object's x from 1 to 2.
Setting Interpolation Values
The fromValue, byValue and toValue properties define the values being interpolated between. All are optional, and no more than two should be non-nil. The object type should match the type of the property being animated.