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

Why don't you fire this method after a random time??? 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];
}
于 2012-01-17T07:43:41.090 に答える