Graphics Reference
In-Depth Information
9
The biggest difference between time and space is that you can't reuse time.
Merrick Furst
In the previous two chapters, we explored the various types of layer animation that can be
implemented using
CAAnimation
and its subclasses. Animation is a change that happens
over time, so
timing
is crucial to the whole concept. In this chapter, we will look at the
CAMediaTiming
protocol, which is how Core Animation keeps track of time.
The
CAMediaTiming
protocol defines a collection of properties that are used to control the
passage of time during an animation. Both
CALayer
and
CAAnimation
conform to this
protocol, so time can be controlled on both a per-layer and per-animation basis.
Duration and Repetition
We briefly mentioned
duration
(one of the
CAMediaTiming
properties) in Chapter 8,
“Explicit Animations.” The
duration
property is of type
CFTimeInterval
(which is a
double-precision floating-point value that represents seconds, just like
NSTimeInterval
),
and it is used to specify the duration for which a single iteration of an animation will run.
What do we mean by a
single iteration
? Well, another property of
CAMediaTiming
is
repeatCount
, which determines the number of iterations that an animation will be repeated
for. The value of
repeatCount
represents the total number of times the animation will be
played. If the
duration
is 2 seconds, and
repeatCount
is set to 3.5 (three-and-a-half
iterations), the total time spent animating will be 7 seconds.