你如何“打乒乓球”? UIView 图像序列动画

发布于 2024-08-03 19:30:16 字数 672 浏览 1 评论 0原文

我有一个 UIImageView,其中加载了一个 png 图像序列。

我的问题是 - 你知道有什么方法可以“乒乓”动画序列吗? 这样它就会从 1-24 向前播放,然后从 24-1 向后播放并循环。

(技术上应该是:1-24 然后 23-1 然后 2-24 然后 23-1...等等)

- (void) loadAnim01 {
mon01 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mon01_01.png"]];
mon01.center = CGPointMake(258,69);
NSMutableArray *array = [NSMutableArray array];
for (int i = 1; i <= 24; i++) 
    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"mon01_%02d.png",i]]];
mon01.animationImages = array;
mon01.animationDuration = 1.0;
mon01.animationRepeatCount = 0;
[self.view addSubview:mon01];
[mon01 release];

}

非常感谢!

I have a UIImageView which has a png image sequence loaded into it.

My question is - Do you know of any way I can "ping pong" the animation sequence?
So that it plays forward from 1-24 then plays backwards from 24-1 and loops.

(technically it should be : 1-24 then 23-1 then 2-24 then 23-1...etc)

- (void) loadAnim01 {
mon01 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mon01_01.png"]];
mon01.center = CGPointMake(258,69);
NSMutableArray *array = [NSMutableArray array];
for (int i = 1; i <= 24; i++) 
    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"mon01_%02d.png",i]]];
mon01.animationImages = array;
mon01.animationDuration = 1.0;
mon01.animationRepeatCount = 0;
[self.view addSubview:mon01];
[mon01 release];

}

Thank a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

套路撩心 2024-08-10 19:30:16
for (int i = 1; i <= 24; i++) {
    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"mon01_%02d.png",i]]];
}
for (int j = 23; j >= 2; j--) {
    [array addObject:[array objectAtIndex:j-1]];  // -1 since arrays are 0-based
}

这会以相反的顺序添加除第一个和最后一个动画之外的所有动画的第二个副本,这应该会给您带来乒乓效果。

for (int i = 1; i <= 24; i++) {
    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"mon01_%02d.png",i]]];
}
for (int j = 23; j >= 2; j--) {
    [array addObject:[array objectAtIndex:j-1]];  // -1 since arrays are 0-based
}

this adds a second copy of all but the first and last animation, in reverse order, which should give you a ping-pong effect.

辞取 2024-08-10 19:30:16

不,Cocoa 中的所有内容都是引用计数的,因此一个对象在多个集合中的成员身份只会有一个实例,除非您使用复制。

No, everything in Cocoa is reference-counted, so membership of an object in multiple collections is only going to have one instance, unless you use copy.

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