【问题标题】:How do you "ping pong" a UIView image sequence animation你如何“乒乓”一个 UIView 图像序列动画
【发布时间】:2009-08-30 04:27:01
【问题描述】:

我有一个 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];

}

非常感谢!

【问题讨论】:

标签: iphone image animation uiimageview sequence


【解决方案1】:
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
}

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多