2012-01-17 88 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

爲什麼不在隨機時間後觸發此方法? 像

//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 2012-01-20 15:32:06

+1

我的榮幸.... – 2012-01-23 15:49:16