2011-06-15 2 views
3

次のコードは、iOS 3.xでビルドしたときに動作します。今では4.xでは動作しません。言い換えれば、私は同じデバイス上で、同一のデバイス上に、同じバージョンの4.xリリースと4.3の両方で構築された同じアプリケーションを実行できます。後者のisAnimatingは、画面がタップされていないか、向きが変わる。4.0 SDKでUIImageView isAnimatingが中断しましたか?

ここに関連コードがあります。私はXcodeでViewベースのテンプレートを使い始めました。

- (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"); 
    } 
} 

誰もがこれを見ていますか?

+0

質問には関係ありませんが、申し訳ありませんが、これは非常に悪いコードです。配列を作成するにはループを使用する必要があります。 – taskinoor

+0

私はMutable配列を混乱させたくありませんでした。それとも、別の方法でそれをやりましたか? – mahboudz

+0

私はこれよりも可変配列を好むでしょう。それは個人的な選択ですが。 – taskinoor

答えて

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; 
} 
関連する問題