Search code examples
iphoneobjective-cioscalayer

Displaying Multiple CALayers one after another continuously for 60 seconds?


I have a situation over here.

I am using AVFoundation to capture the camera frame. Now what i want to do is that for certain frames, i need to display a picture which revolves in a step by step fashion.

What I am trying to do is that I am taking 4 CALayers comprising of front back left and right images of an object and using CALayer time property and group animation property, i want to display all the images one by one after certain milli seconds interval of time so that the continuous images seems to be like an animation.

How to go about it ? Please help me with some coding here.


Solution

  • -(void)startMainAnimation
    {
      //Animationframes is array of images that should be CGImage Type not UIImage..
      //animation Layer that is added above view……
    
    
      CAKeyframeAnimation *frameAnimation = [[CAKeyframeAnimation alloc] init];
      [frameAnimation setKeyPath:@"contents"];
      frameAnimation.calculationMode = kCAAnimationDiscrete;
      [animationLayer setContents:[animationFrames lastObject]];
      frameAnimation.autoreverses = NO;
      frameAnimation.duration = ((float)[animationFrames count])/4.5;;
      frameAnimation.repeatCount = 1;
      [frameAnimation setValues:animationFrames];
      [frameAnimation setRemovedOnCompletion:YES];
      [frameAnimation setDelegate:self];
      [animationLayer addAnimation:frameAnimation forKey:@"contents"];
      [frameAnimation release];
    
    }