连续显示多个CALayer 60秒?

我在这里有一个情况。

我正在使用AVFoundation捕捉相机框架。 现在我想要做的是对于某些帧,我需要显示一个循序渐进的方式旋转的图片。

我想要做的是,我正在采取4个CALayers组成的一个对象的前后左右图像,并使用CALayer时间属性和组animation属性,我想显示所有的图像一个接一个经过一定的毫秒间隔使连续的图像看起来像一个animation。

如何去呢? 请帮我在这里编码。

 -(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]; } 

在Mohit Gupta的pastie链接的基础上回答:

设置您想要图像序列animation的CALayer

 CALayer *animationLayer = [CALayer layer]; [animationLayer setFrame:CGRectMake(125, 0, 240, 300)]; [self.baseLayer addSublayer:animationLayer]; 

定义需要在序列animation中显示的图像arrays

 NSArray *animationFrames = [NSArray arrayWithObjects:(id)[UIImageimageNamed:@"1.png"].CGImage, (id)[UIImage imageNamed:@"2.png"].CGImage, (id)[UIImage imageNamed:@"3.png"].CGImage, nil]; 

使用CAKeyframeAnimation以顺序方式显示图像数组

 CAKeyframeAnimation *frameAnimation = [[CAKeyframeAnimation alloc] init]; [frameAnimation setKeyPath:@"contents"]; frameAnimation.calculationMode = kCAAnimationDiscrete; //mode of transformation of images [animationLayer setContents:[animationFrames lastObject]]; //set the array objects as encounterd frameAnimation.autoreverses = NO; //If set Yes, transition would be in fade in fade out manner frameAnimation.duration = ((float)[animationFrames count])/4.5; //set image duration , it can be predefined float value frameAnimation.repeatCount = HUGE_VAL; //this is for inifinite, can be set to any integer value as well [frameAnimation setValues:animationFrames]; [frameAnimation setRemovedOnCompletion:YES]; [frameAnimation setDelegate:self]; [animationLayer addAnimation:frameAnimation forKey:@"contents"]; //add animation to your CALayer [frameAnimation release]; 

希望这可以帮助