UIImageView是否在4.0 SDK中启动了游戏?

时间:2011-06-15 08:32:53

标签: objective-c ios uiimageview uiimage

以下代码用于在使用iOS 3.x构建时工作。现在使用4.x它不起作用。换句话说,我可以在同一台设备上运行两个相同的应用程序,一个针对每个4.x版本构建,另一个针对4.3构建,而在后者中,isAnimating不会更改值,除非屏幕被点击或者方向变化。

这是相关代码。我开始在Xcode中使用基于视图的模板。

- (void)viewDidLoad {
    [super viewDidLoad];
    iv.animationImages = [NSArray arrayWithObjects:
                                      [UIImage imageNamed:@"timer00.png"],
                                      [UIImage imageNamed:@"timer01.png"],
                                      [UIImage imageNamed:@"timer02.png"],
                                      [UIImage imageNamed:@"timer03.png"],
                                      [UIImage imageNamed:@"timer04.png"],
                                      [UIImage imageNamed:@"timer05.png"],
                                      [UIImage imageNamed:@"timer06.png"],
                                      [UIImage imageNamed:@"timer07.png"],
                                      [UIImage imageNamed:@"timer08.png"],
                                      [UIImage imageNamed:@"timer09.png"],
                                      [UIImage imageNamed:@"timer10.png"],
                                      [UIImage imageNamed:@"timer11.png"],
                                      [UIImage imageNamed:@"timer12.png"],
                                      [UIImage imageNamed:@"timer13.png"],
                                      [UIImage imageNamed:@"timer14.png"],
                                      [UIImage imageNamed:@"timer15.png"],
                                      [UIImage imageNamed:@"timer16.png"],
                                      [UIImage imageNamed:@"timer17.png"],
                                      [UIImage imageNamed:@"timer18.png"],
                                      [UIImage imageNamed:@"timer19.png"],
                                      [UIImage imageNamed:@"timer20.png"],
                                      [UIImage imageNamed:@"timer21.png"],
                                      [UIImage imageNamed:@"timer22.png"],
                                      [UIImage imageNamed:@"timer23.png"],
                                      [UIImage imageNamed:@"timer24.png"],
                                      [UIImage imageNamed:@"timer25.png"],
                                      [UIImage imageNamed:@"timer26.png"],
                                      [UIImage imageNamed:@"timer27.png"],
                                      [UIImage imageNamed:@"timer28.png"],
                                      [UIImage imageNamed:@"timer29.png"],
                                      [UIImage imageNamed:@"timer30.png"],
                                      [UIImage imageNamed:@"timer31.png"],
                                      [UIImage imageNamed:@"timer32.png"],
                                      [UIImage imageNamed:@"timer33.png"],
                                      [UIImage imageNamed:@"timer34.png"],
                                      [UIImage imageNamed:@"timer35.png"],
                                    [UIImage imageNamed:@"timer36.png"],                                      nil];
    iv.animationDuration = 5.0;
    iv.animationRepeatCount = 1;
    [iv startAnimating];
    timer = [NSTimer scheduledTimerWithTimeInterval:0.5 
                                             target:self 
                                           selector:@selector(periodicallyUpdateView) 
                                           userInfo:nil 
                                            repeats:YES];
}

- (void)periodicallyUpdateView {
    if ([iv isAnimating]) {
        NSLog(@"it is animating");
    }
    else {
        NSLog(@"it is NOT animating");
    }
}

还有其他人看到这个吗?

1 个答案:

答案 0 :(得分:1)

如果您设置计时器,这将更有效。您遇到的问题可能不是UIImageView被破坏,而是图像视图需要很长时间才能加载动画。

我推荐这样的东西。

NSTimer *imageTimer;

int animationCount;

- (void)startAnimation
{
      imageTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(switchImage) userInfo:nil repeats:YES];
}

- (void)switchImage
{
       NSString *imageName = [NSString stringWithFormat:@"timer%i" , animationCount];
       UIImage *image = [UIImage imageNamed:imageName];
       someImageView.image = image;
 }