Iphone 随机选择时间间隔。眨眼。通过UIView animateWithDuration:

Iphone 随机选择时间间隔。眨眼。通过UIView animateWithDuration:,iphone,ios,xcode,nstimer,uiviewanimationtransition,Iphone,Ios,Xcode,Nstimer,Uiviewanimationtransition,我想创建一个动画眨眼,在一个随机间隔。就像一个正常的生物会随机眨眼一样 然而这不是我想要它做的,有什么想法吗 - (void)animateFrogEyeOpenClose { if (OpenEye) { [UIView animateWithDuration:0.1 animations:^{ eyeOpenImageView.alpha = 0.0;

我想创建一个动画眨眼,在一个随机间隔。就像一个正常的生物会随机眨眼一样

然而这不是我想要它做的,有什么想法吗

- (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];                  
                     }                   
        ];
    }
}

为什么不在一段随机时间后触发此方法??? 像

//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];
}