Graphics Reference
In-Depth Information
Using Custom Transitions
It is simple to specify the CIFilter you want to use for a transition. To apply the transi-
tion, use the CATransition object's filter parameter to specify the action you want to
use on a particular key. When used, the filter parameter overrides the CATransition
object's type and subtype parameters. If you have specified one of the default transitions
using these other two parameters, they will be ignored when the filter parameter has
been set.
To Delegate or Encapsulate
For most applications, you should encapsulate your custom transition functionality by
implementing it in your own CALayer -derived class. You can, however, use a delegate
method of the CALayer if that is more convenient. That is the only reason to prefer dele-
gation over encapsulation—convenience. For organization and reduced code clutter,
choose encapsulation over delegation, but for the quick and dirty approach, delegation is
sometimes the way to go. There are two different techniques, and therefore function calls,
you can implement, as shown in Table 6-4.
TABLE 6-4 Methods to Use to Encapsulate or Delegate
If you Want To:
Then:
Encapsulate
Override the following method in your CALayer -derived class:
+ (id<CAAction>)defaultActionForKey:(NSString *)aKey
Delegate
Set the layer delegate to point to your controller and implement the
following delegate method:
- (id<CAAction>)actionForLayer:(CALayer *)layer
forKey:(NSString *)key;
It is sometimes quicker and more convenient to simply use a delegate to specify the tran-
sition filter you want to use. If you are implementing a custom transition with a delegate,
first set the delegate for the layer in question in the application's delegate code; for
example:
[layer setDelegate:self];
Then you implement the delegate method for setting an action for a particular key and
layer:
- ( id < CAAction >)actionForLayer:( CALayer *)layer
forKey:( NSString *)key;
In this delegate method, you are provided two items that enable you to specify what kind
of filter to apply to perform your transition: the layer and the key -path string. You have
two options:
.
You simply check to see if the layer object passed in is the one you want to work
with by comparing memory addresses with the == operator.
 
Search WWH ::




Custom Search