CAAnimation不会动画我的图像序列

时间:2012-02-07 18:38:50

标签: objective-c caanimation

我在使用CAAnimation制作动画时出现问题,它似乎没有给我任何错误,但它不是动画。我很困惑

NSMutableArray *animationImages = [NSMutableArray array];
//Adding images into array
for (int i=0;i<=5;i++){
    UIImage *imgfile = [NSString stringWithFormat:@"%@/ConusOverlay/%d_ConusOverlay.gif",documentsPath,i];
    [animationImages addObject: imgfile];
}

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

NSMutableArray *animationSequenceArray = [NSMutableArray array];
for (UIImage *image in animationImages) {
    [animationSequenceArray addObject:image]; //<--Does this have to be (id)image.CGImage ?, if I am correct you are unable to add CGImage to an array
}
animationSequence.values = animationSequenceArray;
[mlLayer.contents addAnimation:animationSequence forKey:@"contents"];

1 个答案:

答案 0 :(得分:1)

CoreAnimation通常需要CGImageRef s而非UIImages。尝试按照建议将image替换为(id)image.CGImage。数组可以存储CGImageRef s!