使用CAAnimation动画图像

时间:2011-05-05 12:37:22

标签: iphone objective-c animation core-animation

是否可以使用CAAnimation实现动画的图像序列?我不想使用UIImageView ......

我需要类似于UIImageView的东西,我们可以设置imageView.animationImages并调用startAnimation ...但是使用CAAnimation

1 个答案:

答案 0 :(得分:7)

CAKeyframeAnimation *animationSequence = [CAKeyframeAnimation animationWithKeyPath: @"contents"];
animationSequence.calculationMode = kCAAnimationLinear;
animationSequence.autoreverses = YES;
animationSequence.duration = kDefaultAnimationDuration;
animationSequence.repeatCount = HUGE_VALF;

NSMutableArray *animationSequenceArray = [[NSMutableArray alloc] init];
for (UIImage *image in self.animationImages) 
{
    [animationSequenceArray addObject:(id)image.CGImage];
}
animationSequence.values = animationSequenceArray;
[animationSequenceArray release];
[self.layer addAnimation:animationSequence forKey:@"contents"];