CAAnimation 没有为我的图像序列设置动画

发布于 2025-01-03 12:48:47 字数 998 浏览 0 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷不放纵 2025-01-10 12:48:47

CoreAnimation 通常采用 CGImageRef,而不是 UIImages。尝试按照您的建议将 image 替换为 (id)image.CGImage 。数组可以存储 CGImageRef!

CoreAnimation usually takes CGImageRefs and not UIImages. Try replacing the image with the (id)image.CGImage as you suggested. Arrays can store CGImageRefs!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文