更新#1:
你的班级需要一个变量:
BOOL _animationFinished;
然后您可以对动画使用以下方式:
float newAlpha = 0.0;
//TODO:Check if the previous animation has finished
if (_animationFinished == false) return;
if(answer.alpha==0.0) {
newAlpha = 1.0;
} else if(answer.alpha==1.0) {
newAlpha = 0.0;
}
[UIView animateWithDuration:1.0f animations:^{ answer.alpha = newAlpha; _animationFinished = false; } completion:^(BOOL finished){ _animationFinished = true; }];
它必须是工作。
原来的
在这种情况下,我总是检查动画的主题,如下所示:
float newAlpha = 0.0;
//TODO:Check if the previous animation has finished
if (answer.alpha > 0.f || answer.alpha < 1.f) return; // it is always good enough for me
// ...or with AND it will cause the same effect:
// if (answer.alpha > 0.f && answer.alpha < 1.f) return;
if(answer.alpha==0.0) {
newAlpha = 1.0;
} else if(answer.alpha==1.0) {
newAlpha = 0.0;
}
[UIView animateWithDuration:1.0 animations:^{
answer.alpha = newAlpha;
}];