Graphics Reference
In-Depth Information
The odd thing about the
transform.rotation
property is that it
doesn't really exist.
It
can't
exist because
CATransform3D
isn't an object; it's a
struct
and so cannot have KVC
(Key-Value Coding) compliant properties.
transform.rotation
is actually a
virtual
property that
CALayer
provides to simplify the process of animating transforms.
You cannot set properties like
transform.rotation
or
transform.scale
directly; they
can only be used for animation. When you animate these properties, Core Animation
automatically updates the
transform
property with the actual value that your changes
necessitate by using a class called
CAValueFunction
.
CAValueFunction
is used to convert the simple floating-point value that we assign to the
virtual
transform.rotation
property into the actual
CATransform3D
matrix value that is
needed to position the layer. You can change the value function used by a given
CAPropertyAnimation
by setting its
valueFunction
property. The function you specify
will override the default.
CAValueFunction
seems
like it could be a useful mechanism for animating properties that
cannot naturally be summed together or interpolated (such as transform matrices), but
because the implementation details of
CAValueFunction
are private, it's not currently
possible to subclass it to create new value functions. You can only use the functions that
Apple already make available as constants (which currently all relate to the transform
matrix's virtual properties and are therefore somewhat redundant since the default actions
for those properties already use the appropriate value functions).
Although
CABasicAnimation
and
CAKeyframeAnimation
only target individual properties,
multiple such animations can be gathered together using a
CAAnimationGroup
.
CAAnimationGroup
is another concrete subclass of
CAAnimation
that adds an
animations
array property, to be used for grouping other animations. Let's test this out by grouping the
keyframe animation in Listing 8.6 together with another basic animation that adjusts the
layer background color (see Listing 8.10). Figure 8.3 shows the result.
Adding an animation group to a layer is not fundamentally different from adding the
animations individually, so it's not immediately clear when or why you would use this
class. It provides
some
convenience in terms of being able to collectively set animation
durations, or add and remove multiple animations from a layer with a single command, but
it's usefulness only really becomes apparent when it comes to
hierarchical timing
, which is
explained in Chapter 9.
Listing 8.10
Grouping a Keyframe and Basic Animation Together
- (
void
)viewDidLoad
{
[
super
viewDidLoad
];