Случайный интервал времени. Моргнуть глазом Через UIView animateWithDuration: - PullRequest
0 голосов
/ 17 января 2012

Я хотел бы создать анимацию, чтобы моргнуть глазом, через произвольный интервал.Точно так же, как нормальное существо, которое будет мигать случайным образом.

Однако это не то, чего я хотел, какие-либо мысли?

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

1 Ответ

2 голосов
/ 17 января 2012

Почему бы вам не запустить этот метод после случайного времени ??? как

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