Kernel animation sequence

How would I start creating a sequence of images using basic animation. I would like to:

add image1 for 1 second and then delete image

add image2 for 2 seconds and then delete image

add image1 for 3 seconds then delete

CGImageRef image1 = [self getImage1]; CALayer *image1Layer = [CALayer layer]; image1Layer.bounds = CGRectMake(0, 0, 480, 320); image1Layer.position = CGPointMake(0, 0); image1Layer.contents = (id)image1; CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"animation"]; animation1.repeatCount = 0; animation1.duration = 2.0; animation1.removedOnCompletion = YES; // i would like to remove image here animation1.beginTime = AVCoreAnimationBeginTimeAtZero; [image1Layer addAnimation:animation1 forKey:nil]; 

The above code adds an image but does not delete it.

Greetings

+4
source share
1 answer

The easiest way is to use CABasicAnimation for the content key:

 CABasicAnimation *animation = [CABasicAnimation animation]; animation.fromValue = (id)[UIImage imageNamed:@"image1.png"].CGImage; animation.toValue = (id)[UIImage imageNamed:@"image2.png"].CGImage; animation.duration = 1.0f; animation.repeatCount = HUGE_VAL; // animation.autoreverses = YES; [image1Layer addAnimation:animation forKey:@"contents"]; 

This animation will infinitely change the contents of the layer between image1 and image2. You might want to set the autoreverses property for autoreverses transitions - check the animation in any way and select the option you want.

+8
source

All Articles