2012-01-17 10 views
0

私は無作為の間隔で目を点滅させるアニメーションを作りたいと思います。ちょうどそれがランダムに点滅する通常の人のように。ランダムな時間間隔。目を点滅させる。 UIViewを通してanimateWithDuration:

しかしこれは、私はそれは、どんな考えをやってみたかったものではありませんか?

- (void)animateFrogEyeOpenClose 
{ 
    if (OpenEye) { 
     [UIView animateWithDuration:0.1 

        animations:^{ 
         eyeOpenImageView.alpha = 0.0; 
         eyeCloseImageView.alpha = 1.0; 
        } 
        completion:^(BOOL completed){ 
         if (completed) 
          OpenEye = 0; 
          CloseEye = 1; 
          [self animateFrogEyeOpenClose];     
        }      
     ]; 
    } 
    else 
    { 
     [UIView animateWithDuration:0.1 

        animations:^{ 
         eyeOpenImageView.alpha = 1.0; 
         eyeCloseImageView.alpha = 0.0; 
        } 
        completion:^(BOOL completed){ 
         if (completed) 
          OpenEye = 1; 
         CloseEye = 0; 
          [self animateFrogEyeOpenClose];     
        }     
     ]; 
    } 
} 

答えて

2

ランダムな時間の後でこのメソッドを起動しないでください。 like

//call this method for the first time 
[self fireMethod:nil]; 
// 

- (void)fireMethod:(id)sender{ 
    int rand = arc4random(); //set the random no acc. to your requirement 
    [self animateFrogEyeOpenClose]; 
    [self performSelector:@selector(fireMthod:) withObject:nil afterDelay:rand]; 
} 
+0

ありがとうございます、私はそれが動作するように変更しました。 – Desmond

+1

私の喜び.... –

関連する問題