Graphics Reference
In-Depth Information
You are currently limited to these four basic
CATransition
types, but there are some ways
that you can achieve additional transition effects, as covered later in the chapter.
The default transition type is
kCATransitionFade
, which creates a smooth crossfade
between the previous layer appearance and the new appearance after you have modified its
properties or contents.
We made use of the
kCATransitionPush
type in the custom action example in Chapter 7;
this slides the new layer appearance in from the side, pushing the old one out of the
opposite side.
kCATransitionMoveIn
and
kCATransitionReveal
are similar to
kCATransitionPush
;
they both implement a directional swipe animation, but with subtle differences;
kCATransitionMoveIn
moves the new layer appearance in over the top of the previous
appearance, but doesn't push it out to the side like the push transition, and
kCATransitionReveal
slides the old appearance out to reveal the new one instead of
sliding the new one in.
The latter three standard transition types are inherently directional in nature. By default,
they slide from the left, but you can control their direction using the
subtype
property,
which accepts one of the following constants:
kCATransitionFromRight
kCATransitionFromLeft
kCATransitionFromTop
kCATransitionFromBottom
A simple example of using
CATransition
to animate a nonanimatable property is shown in
Listing 8.11. Here we are changing the
image
property of a
UIImage
, which cannot
normally be animated using either implicit animation or a
CAPropertyAnimation
because
Core Animation doesn't know how to interpolate between images. By using a crossfade
transition applied to the layer, however, we make it possible to smoothly animate the
change regardless of the content type (see Figure 8.4). Try changing the transition
type
constant to see the other possible effects.
Listing 8.11
Animating a
UIImageView
Using
CATransition
@interface
ViewController ()
@property
(
nonatomic
,
weak
)
IBOutlet
UIImageView
*imageView;
@property
(
nonatomic
,
copy
)
NSArray
*images;
@end
@implementation
ViewController
- (
void
)viewDidLoad
{