Graphics Reference
In-Depth Information
self
.images =
@[
[
UIImage
imageNamed
:
@"Anchor.png"
],
[
UIImage
imageNamed
:
@"Cone.png"
],
[
UIImage
imageNamed
:
@"Igloo.png"
],
[
UIImage
imageNamed
:
@"Spaceship.png"
]
]
;
}
- (
IBAction
)switchImage
{
[
UIView
transitionWithView
:
self
.imageView
duration
:
1.0
options
:
UIViewAnimationOptionTransitionFlipFromLeft
animations
:^{
//cycle to next image
UIImage
*currentImage =
self
.imageView.
image
;
NSUInteger
index = [
self
.images
indexOfObject
:currentImage];
index = (index +
1
) % [
self
.images
count
];
self
.imageView.
image
=
self
.images[index];
}
completion
:
NULL
];
}
@end
The documentation in some places seems to imply that since iOS 5 (which introduced the
Core Image framework), it might be possible to use
CIFilter
in conjunction with the
filter
property of
CATransition
to create additional transition types. As of iOS 6,
however, this still does not work. Attempting to use Core Image filters with
CATransition
has no effect. (This
is
supported on Mac OS, which probably accounts for the documentation
discrepancies.)
For this reason, you are forced to choose between using a
CATransition
or the
UIView
transition method, depending on the effect you want. Hopefully, a future version of iOS will
add support for Core Image transition filters and so make the full range of Core Image
transition animations available via
CATransition
(and maybe even add the ability to create
new ones).
That doesn't mean that it's impossible to achieve custom transition effects on iOS, though. It
just means that you have to do a bit of extra work. As mentioned earlier, the basic principle
of a transition animation is that you take a snapshot of the current state of the layer and then
apply an animation to that snapshot while you change the layer behind the scenes. If we can
figure out how to take a snapshot of our layer, we can perform the animation ourselves using
ordinary property animations without using
CATransition
or UIKit's transition methods at
all.