连续显示多个CALayers一个又一个60秒?(Displaying Multiple CALaye

2019-09-18 14:12发布

我有一个情况在这里。

我使用AVFoundation捕获相机框架。 现在我想要做的是,对于某些帧,我需要显示其在旋转一步步的时尚图片。

我所要做的是,我服用4个CALayers包含前方的物体的背面左图像和右图像,并且使用的CALayer时间属性和组动画属性,我要通过一个特定毫秒的时间间隔后,以显示所有的图像的一个时间,使得连续图像看起来像一个动画。

如何做呢? 请帮我在这里一些编码。

Answer 1:

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

}


Answer 2:

答莫希特Gupta的pastie联系的基础上:

设置CALayer的要在其上的图像序列动画

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

限定在序列动画显示所需图像的阵列

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

希望这可以帮助



文章来源: Displaying Multiple CALayers one after another continuously for 60 seconds?