我想创建一个动画,以随机的间隔眨眼。就像一个随意闪烁的正常生物。
然而,这不是我想要做的,有什么想法吗?
- (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];
}
];
}
}
答案 0 :(得分: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];
}