Created
April 12, 2011 12:24
-
-
Save veritech/915414 to your computer and use it in GitHub Desktop.
Using CAKeyFrameAnimation to animate images in a CALayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create the layer | |
layer = [CALayer layer]; | |
//Configure the animation | |
animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"]; | |
[animation setCalculationMode:kCAAnimationDiscrete]; | |
[animation setDuration:2.0f]; | |
[animation setRepeatCount:HUGE_VALF]; | |
[animation setValues:/* your NSArray of CGImageRefs*/]; | |
//Add the animation to the layer | |
[layer addAnimation:animation | |
forKey:@"contents" | |
]; | |
[layer setFrame:/* The frame of the layer*/]; | |
//Add to the super layer | |
[parentLayer addSublayer:layer]; |
Thanks, it works. And the [animation setValues: /**/];
just like this:
[animation setValues:[NSArray arrayWithObjects:(id)[UIImage imageNamed:@"i1"].CGImage, (id)[UIImage imageNamed:@"i2"].CGImage, (id)[UIImage imageNamed:@"i3"].CGImage, nil]];
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this gist! my little hero is now an animated layer :)