Graphics Reference
In-Depth Information
delegate (used to get feedback about the animation state), and a removedOnCompletion
flag, used to indicate whether the animation should automatically be released after it has
finished (this defaults to YES , which prevents your application's memory footprint from
spiraling out of control). CAAnimation also implements a number of protocols, including
CAAction (allowing any CAAnimation subclass to be supplied as a layer action) and
CAMediaTiming (which is explained in detail in Chapter 9, “Layer Time”).
CAPropertyAnimation acts upon a single property, specified by the animation's keyPath
value. A CAAnimation is always applied to a specific CALayer , so the keyPath is relative to
that layer. The fact that this is a key path (a sequence of dot-delimited keys that can point to
an arbitrarily nested object within a hierarchy) rather than just a property name is
interesting because it means that animations can be applied not only to properties of the
layer itself, but to properties of its member objects, and even virtual properties (more on
this later).
CABasicAnimation extends CAPropertyAnimation with three additional attributes:
id fromValue
id toValue
id byValue
These are fairly self-explanatory: fromValue represents the value of the property at the start
of the animation; toValue represents its value at the end of the animation; byValue
represents the relative amount by which the value changes during the animation.
By combining these three attributes, you can specify a value change in various different
ways. The type is defined as id (as opposed to something more specific) because property
animations can be used with a number of different property types, including numeric
values, vectors, transform matrices, and even colors and images.
A property of type id can contain any NSObject derivative, but often you will want to
animate property types that do not actually inherit from NSObject , which means that you
will need to either wrap the value in an object (known as boxing ) or cast it to an object
(known as toll-free bridging ), which is possible for certain Core Foundation types that
behave like Objective-C classes, even though they aren't. It's not always obvious how to
convert the expected data type to an id -compatible value, but the common cases are listed
in Table 8.1.
Table 8.1 Boxing Primitive Values for Use in a CAPropertyAnimation
Type
Object Type
Code Example
CGFloat
NSNumber
id obj = @(float);
CGPoint
NSValue
id obj = [NSValue valueWithCGPoint:point);
CGSize
NSValue
id obj = [NSValue valueWithCGSize:size);
CGRect
NSValue
id obj = [NSValue valueWithCGRect:rect);
Search WWH ::




Custom Search