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"];
I'm having trouble with animating with CAAnimation, it doesn't seem to give me any errors but it isn't animating. I'm confused
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"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CoreAnimation 通常采用 CGImageRef,而不是 UIImages。尝试按照您的建议将
image
替换为(id)image.CGImage
。数组可以存储 CGImageRef!CoreAnimation usually takes
CGImageRef
s and notUIImages
. Try replacing theimage
with the(id)image.CGImage
as you suggested. Arrays can storeCGImageRef
s!