你如何“打乒乓球”? UIView 图像序列动画
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这会以相反的顺序添加除第一个和最后一个动画之外的所有动画的第二个副本,这应该会给您带来乒乓效果。
this adds a second copy of all but the first and last animation, in reverse order, which should give you a ping-pong effect.
不,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.