gpt4 book ai didi

iphone - 带有帧数组的 CABasicAnimation

转载 作者:行者123 更新时间:2023-11-29 04:25:42 25 4
gpt4 key购买 nike

我有一个带有 .fromValue.toValueCABasicAnimation,它们在包含 202 个图像的 PNG 图像中移动,并按顺序显示它们一个

我还使用CALayer来保存image.png

按顺序传递所有图像的问题我想按帧显示图像,将其放入 NSArray

这是我的代码:

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];
anim.fromValue = [NSNumber numberWithInt:1];
anim.toValue = [NSNumber numberWithInt:203];
anim.duration = 1.75f;
anim.repeatCount = HUGE_VALF;
anim.autoreverses = YES;
[myImage addAnimation:anim forKey:nil];

帧数组是:

frames =   (753, 377, 798, 422)  ,
(706, 377, 751, 422) ,
(659, 377, 704, 422) ,
(612, 377, 657, 422) ,
(565, 377, 610, 422) ,
(518, 377, 563, 422) ,
(518, 424, 563, 468) ,
(471, 424, 516, 468) ,
(424, 424, 469, 468) ,
(471, 377, 516, 422) ,
(424, 377, 469, 422) ,
(377, 377, 422, 422) ,
(330, 377, 375, 422) ,

等等......

有什么想法吗?

最佳答案

与帧数组类似,您可以将所有需要的图像(帧)添加到 UIImageView 中。这是示例:

NSArray *images = [NSArray arrayWithObjects: 
[UIImage imageNamed:@"frame753.png"],
[UIImage imageNamed:@"frame377.png"],
[UIImage imageNamed:@"frame798.png"],

nil];
yourImageView.animationImages = images;
yourImageView.animationDuration = 1.75;
yourImageView.animationRepeatCount = 0;
[yourImageViewstartAnimating];

希望这对您有所帮助。

关于iphone - 带有帧数组的 CABasicAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12364415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com