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

1 回答 1

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];
}
于 2012-01-17T07:43:41.090 回答