使用CAAnimation动画图像

Cha*_* SP 2 iphone animation core-animation objective-c

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

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

Cha*_* SP 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"];
Run Code Online (Sandbox Code Playgroud)