2012-02-07 50 views
0

我在使用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

CoreAnimation通常需要CGImageRef秒且不UIImages。按照您的建議,嘗試使用(id)image.CGImage替換image。陣列可以存儲CGImageRef s!

+0

非常感謝你的工作,我將[animationSequenceArray addObject:image]更改爲[animationSequenceArray addObject:(id)image.CGImage。精美的作品,再次感謝。 – 2012-02-07 19:02:35