1

我这边有情况。

我正在使用 AVFoundation 来捕获相机帧。现在我想要做的是,对于某些帧,我需要显示一个逐步旋转的图片。

我想要做的是我正在拍摄 4 个 CALayers,包括一个对象的前后左右图像,并使用 CALayer 时间属性和组动画属性,我想在一定的毫秒间隔后一张一张地显示所有图像时间使连续的图像看起来像动画。

怎么办?请帮助我在这里进行一些编码。

4

2 回答 2

1

根据 Mohit Gupta 的粘贴链接回答:

设置你想要图像序列动画的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];

希望这可以帮助

于 2012-06-27T06:29:15.190 回答
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];

}
于 2012-06-27T05:34:49.817 回答