Graphics Reference
In-Depth Information
One possibility is that the property values could be the same as if the animation was not
attached at all, that is, the value would be whatever was defined in the model layer. (See
Chapter 7, “Implicit Animations,” for an explanation of layer model versus presentation.)
Another option is that the properties could take on the value of the first frame of the
animation prior to it beginning and retain the last frame after it has ended. This is known as
filling,
because the animation's start and end values are used to fill the time before and after
the animation's duration.
This behavior is left up to the developer; it can be controlled using the
fillMode
property
of
CAMediaTiming
.
fillMode
is an
NSString
and accepts one of the following constant
values:
kCAFillModeForwards
kCAFillModeBackwards
kCAFillModeBoth
kCAFillModeRemoved
The default is
kCAFillModeRemoved
, which sets the property values to whatever the layer
model specifies when the animation isn't currently playing. The other three modes fill the
animation forward, backward, or both so that the animatable properties take on the start
value specified in the animation before it begins and/or the end value once it has finished.
This provides an alternative solution to the problem of having to manually update a layer
property to match the end value of an animation to avoid snap-back when the animation
finishes (mentioned in Chapter 8). Bear in mind, however, that if you intend to use it for
this purpose, you will need to set
removeOnCompletion
to
NO
for your animation. You will
also need to use a non-nil key when adding the animation, so that you can manually remove
it from the layer when you no longer need it.
In Chapter 3, “Layer Geometry,” you learned how each layer has a spatial coordinate
system that is defined relative to its parent in the layer tree. Animation timing works in a
similar way. Each animation and layer has its own hierarchical concept of time, measured
relative to its parent. Adjusting the timing for a layer will affect its own animations and
those of its sublayers, but not its superlayer. The same goes for animations that are grouped
hierarchically (using nested
CAAnimationGroup
instances).
Adjusting the
duration
and
repeatCount/repeatDuration
properties for a
CALayer
or
CAGroupAnimation
will not affect its children's animations. The
beginTime
,
timeOffset
,
and
speed
properties
will
impact child animations, however. In hierarchical terms,
beginTime
specifies a time offset between when the parent layer (or parent animation in
the case of a grouped animation) starts animating and when the object in question should
begin its own animation. Similarly, adjusting the
speed
property of a
CALayer
or
CAGroupAnimation
will apply a scaling factor to the animation speed for all of the
children, as well.