Graphics Reference
In-Depth Information
LISTING 2-2
Animating the Background Color from Red to Green on iPhone
- (
CABasicAnimation
*)backgroundColorAnimation;
{
CABasicAnimation
*anim =
[
CABasicAnimation
animationWithKeyPath
:@”backgroundColor”
];
[anim
setDuration
:5.0];
[anim
setFromValue
:(
id
)[[
UIColor redColor
] CGColor]];
[anim setToValue:(
id
)[[
UIColor greenColor
] CGColor]];
return
anim;
}
Color fields that you can animate include
.
backgroundColor
The layer's background color.
.
borderColor
The color of the layer's border.
.
shadowColor
The color of the layer's shadow. At the time of this writing, the
shadowColor
prop-
erty is not available on the iPhone.
Motion
When you want motion on the screen, Core Animation provides rectangles and points in
each layer that you can animate. Motion fields you can animate include
.
anchorPoint
The default
anchorPoint
of a layer is
0.5,0.5
, which indicates the center of the
layer is the
anchorPoint
. If you change the
anchorPoint
to
0.0,0.0
, it will be
located at the bottom-left corner.
.
bounds
The
bounds
property animates the shape of the bounding rectangle. It does not
affect the layer's position.
.
frame
The
frame
property is not animated in a layer. You can set this parameter and the
layer's internal value with change; however, you won't see the actual animation. If
you want to animate a layer's bounds, that is, its bounding rectangle, use the
bounds
property. If you want to change the position, use the
position
property. On views
and windows, setting
frame
causes the bounding frame to animate.