An object that provides basic, single-keyframe animation capabilities for a layer property.
- iOS 2.0+
- macOS 10.5+
- tvOS 9.0+
For example, you can animate a layer's scalar (i.e. containing a single value) properties such as its
opacity. The following code fades in a layer by animating its opacity from
Non-scalar properties, such as
backgroundColor, can also be animated. Core Animation will interpolate between the
fromValue color and the
toValue color. The following animation 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
fromValue as arrays. The following animation moves a layer from
(0, 0) to
keyPath can access the individual components of a property. For example, the following code stretches a layer by animating its
x from 1 to 2:
Setting Interpolation Values
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.
The interpolation values are used as follows:
All properties are
nil. Interpolates between the previous value of
keyPathin the target layer’s presentation layer and the current value of
keyPathin the target layer’s presentation layer.