Graphics Reference
In-Depth Information
Animation and Layers
In Core Animation, timing is everything. When you animate a layer property, you have
to decide how long the animation should take, how it should move (easing), whether it
should return to its starting value, and how many different values the property should
have during its run (basic animation versus keyframe animation). You specify each of
these attributes by setting values for the animation properties. However, these values are
not specified in the layer itself, but rather in the CAAnimation animation object and its
derivatives, CABasicAnimation and CAKeyframeAnimation .
Once again, the layer is a model object,
not a view object in the MVC design
pattern. The layer contains attributes
that describe the layer: position, frame,
colors, and so on. Similarly, an anima-
tion describes the animation itself, but
the properties you set relate to the layer
you are animating. You cause a layer to animate by adding the animation object to the
layer object with a call to -addAnimation:forKeyPath . Similarly, you stop a layer from
animating by removing the animation from the layer with a call to -removeAnimation:
forKeyPath , although the default behavior is for an animation to be removed automati-
cally after it has run.
NOTE
Basic animation and keyframe animation are
covered in great detail in their respective
chapters: Chapter 3, “Basic Animations,”
and Chapter 4, “Keyframe Animation.”
Animation Pacing
As previously mentioned, Core Animation gives you a lot of functionality for free. When
you perform animation without Core Animation, you iterate a property value using a
loop. Doing so produces an animation that changes in a linear fashion. This is to say that
the animation animates at a constant rate. Each step in the animation is reached in an
exactly subdivided increment of the total duration. In Core Animation, however, the
default animating functionality causes an animation to ease in and ease out. This means
that the animation starts out slow, speeds up in the middle, and then slows again when it
gets close to its destination value. This concept of easing causes an animation to appear
more natural and organic—whereas a linear animation has a more static feel because the
property changes at an exact and rigid constant rate.
Core Animation gives you a great level
of flexibility when it comes to anima-
tion pacing. For the vast majority of
applications, you will be satisfied with
the built-in pacing functions. These
include
NOTE
The default animating functionality is ease
in/ease out, but this is not obvious
because if you check the value of the
timingFunction parameter of your anima-
tion, you will find that it is set to nil, which
might indicate to you that the animation is
using linear animation as the default. This is
not the case.
.
Linear, for when you do want that
more static feel.
 
Search WWH ::




Custom Search