Re: How do I get CATransition to actually work?
Re: How do I get CATransition to actually work?
- Subject: Re: How do I get CATransition to actually work?
- From: Scott Anguish <email@hidden>
- Date: Sat, 27 Oct 2007 04:14:01 -0400
In Leopard, the new CATransition class supposedly animates a
CoreImage transition onto a layer. Has anyone figured out how to get
this to work in a similar style to how the transitions work in
CoreImage Fun House?
Here is the implementation code of a NSView Subclass that replaces the
standard "contents" animation (a fade) with a moveIn from right
Transition
Make a new view class (TransitionView), paste in the following code
(replacing all the implementation code in the template), set the
header up accordingly. Make a new custom view in IB, and set the class
to TransitionView. You'll need to find your own images (image.png and
Blue.tiff in the example.. easy to change though) and add them to the
project
Add two buttons, one labeled purple, one labeled blue. Set them so
that their target object is the view, and so that the appropriate ones
trigger the appropriate changeTo...: action. It does it the easiest
way, by creating an NSDictionary and setting the transition animation
as the value for the "contents" key. This replaces the stock implicit
animation with the new one.
Anyways, all of that is for the benefit of list readers.. I've sent
you the code.
Does this help at all?
Can you please file a bug asking for an example in the Core Animation
Cookbook documentation on how to "use a custom filter as a transition"?
- (void)awakeFromNib
{
// setup the layers
[self setupLayers];
}
- (void)setupLayers
{
rootLayer =[[CALayer layer] retain];
// set the layer for the view class that we've customized
[self setLayer:rootLayer];
// turn on layer-hosting for the view. The order of these two
// methods is important. For layer-hosting you want to set the layer
// and then turn on the layer support for the view. For layer-
backing, you
// do the reverse
[self setWantsLayer:YES];
rootLayer.backgroundColor=CGColorCreateGenericRGB(1.0f,1.0f,1.0f,1.0f);
rootLayer.borderWidth=1.0;
frontLayer=[[CALayer layer] retain];
frontLayer.bounds=rootLayer.bounds;
frontLayer.position=rootLayer.position;
frontLayer.contentsGravity=kCAGravityCenter;
[rootLayer addSublayer:frontLayer];
[self changeToBlue:self];
[self setNewContentsAnimation:self];
}
-(void)setNewContentsAnimation:(id)sender
{
CATransition *theTransition=[CATransition animation];
theTransition.type=kCATransitionMoveIn;
theTransition.subtype=kCATransitionFromRight;
NSMutableDictionary *theActions=[NSMutableDictionary
dictionaryWithDictionary:[frontLayer actions]];
[theActions setObject:theTransition forKey:@"contents"];
frontLayer.actions=theActions;
}
- (void)changeToPurple:(id)sender;
{
NSImage *animatedImage=[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]];
frontLayer.contents=(id)[[[animatedImage representations]
objectAtIndex:0] CGImage];
[animatedImage release];
}
- (void)changeToBlue:(id)sender
{
NSImage *animatedImage=[[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"Blue" ofType:@"tiff"]];
frontLayer.contents=(id)[[[animatedImage representations]
objectAtIndex:0] CGImage];
[animatedImage release];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden