Graphics Reference
In-Depth Information
LISTING 6-15
Continued
}
else
{
CGRect newFrame =
CGRectMake ((contentRect. size . width / 2) - 100.0,
(contentRect. size . height / 2) - 100.0,
contentRect. size . width - 200.0,
contentRect. size . height - 200.0);
[transitionLayer setBounds :newFrame];
}
toggle = !toggle;
}
@end
The -doTransition method is identical regardless of which method you use to implement
the transition filter. It uses a variable called toggle that keeps track of whether the layer
covers the whole content area or its reduced size. The call to -setBounds on the layer
causes the transition animation to occur. When the toggle is set, we transition to the
content view frame, and we transition to the smaller frame when it isn't set. We then
toggle the toggle variable.
To summarize, the main differences between encapsulation and delegation follow:
.
Encapsulation requires you to create your own CALayer -derived layer class that will
override + (id<CAAction>)defaultActionForKey:(NSString *)key; .
.
Delegation requires that your
application delegate implements
-(id<CAAction>)actionForLayer:
(CALayer *)layer after setting the
layer's delegate to the AppDelegate
instance, usually self .
NOTE
It's up to you whether you delegate or encap-
sulate. We tend to choose the encapsulation
route as it makes things tidy. However, it is
completely legitimate to use the delegation
method should that prove to be cleaner or
more convenient.
Summary
Whether providing a simple view effect, adding animations based on user interaction,
changing filter parameters, or changing the default transition to be something more inter-
esting, Core Image filters are a powerful and valuable component in the Core Animation
toolbox.
 
 
Search WWH ::




Custom Search