-1

画像の配列で構成されるアニメーションがあり、その上で実行します

[myUIImageView startAnimating]

アニメーションを 1 回実行してから、3 秒間停止してから繰り返します。

このアニメーションを別のスレッドで実行する必要があるので、

NSThread *animationThread = [[NSThread alloc] initWithTarget:self selector:@selector(startAnimTask) withObject:nil waitUntilDone:NO]; 
[animationThread start];

私のviewDidLoadで、次に

-(void) startAnimTask {

   //create array of images here; animationDuration (3) and animationRepeatCount (1)
   [self setUpAnimation];

   while (true){
       [myUIImageView startAnimating];
       usleep(3);        
       [myUIImageView stopAnimating];
       usleep(3);    
   }
}

この方法を使用すると、メモリ警告が表示されます。また、MainThread で開始と停止を実行しようとしましたが、うまくいきませんでした。

何か案は?

4

4 に答える 4

5

これを行う:

 [myUIImageView startAnimating];
 [self performSelector:@selector(startAnimTask) 
         withObject:nil 
         afterDelay:(myUIImageView.animationDuration+3.0)];

現在のセレクターは次のとおりです。

 -(void)startAnimTask
 {
   [myUIImageView startAnimating];
   //repeat again then add above selector code line here
 }
于 2012-08-30T11:34:39.573 に答える
1

私はあなたがこれで行くことができると思います:

  [self performSelector:@selector(startAnimTask) 
             withObject:nil 
             afterDelay:0.1];

  [self performSelector:@selector(startAnimTask) 
             withObject:nil 
             afterDelay:3.0];

startAnimTaskメソッドで、アニメーション ロジック コードを記述します。

コーディングをお楽しみください :)

于 2012-08-30T11:32:34.107 に答える
1

UI はスレッド セーフではないため、UI 呼び出しはメイン スレッドでのみ実行する必要があります。

于 2012-08-30T11:25:40.063 に答える
1

タスクを完了するには、次のアプローチを試してください。

[self performSelector:@selector(myTask) 
             withObject:nil 
             afterDelay:3.0];

-(void)myTask{

//Write your logic for animation

}
于 2012-08-30T11:45:18.407 に答える