0

我有一个CABasicAnimation带有 a.fromValue和 a.toValue的带有 202 个图像的 PNG 图像移动并一张一张地显示它们

我也曾经CALayer拿着 image.png

它按顺序传递所有图像的问题我想按我将放入的帧显示图像NSArray

这是我的代码:

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];
anim.fromValue = [NSNumber numberWithInt:1];
anim.toValue = [NSNumber numberWithInt:203];
anim.duration = 1.75f;
anim.repeatCount = HUGE_VALF;
anim.autoreverses = YES; 
[myImage addAnimation:anim forKey:nil];

帧数组是:

frames =   (753, 377, 798, 422)  ,
  (706, 377, 751, 422)  ,
  (659, 377, 704, 422)  ,
  (612, 377, 657, 422)  ,
  (565, 377, 610, 422)  ,
  (518, 377, 563, 422)  ,
  (518, 424, 563, 468)  ,
  (471, 424, 516, 468)  ,
  (424, 424, 469, 468)  ,
  (471, 377, 516, 422)  ,
  (424, 377, 469, 422)  ,
  (377, 377, 422, 422)  ,
  (330, 377, 375, 422)  ,

等等 ....

有任何想法吗 ??

4

1 回答 1

1

与您的帧数组类似,您可以将所有需要的图像(帧)添加到 UIImageView。这是示例:

NSArray *images = [NSArray arrayWithObjects: 
              [UIImage imageNamed:@"frame753.png"],
              [UIImage imageNamed:@"frame377.png"],
              [UIImage imageNamed:@"frame798.png"], 

              nil];
yourImageView.animationImages = images; 
yourImageView.animationDuration = 1.75; 
yourImageView.animationRepeatCount = 0;
[yourImageViewstartAnimating]; 

希望这可以帮助。

于 2012-09-11T12:33:57.933 回答