更新时间:2023-02-16 14:28:32
您正在做的是,您只需在块外设置启用/禁用启用.这是错误的,一旦该方法将被调用,它就会执行,因此在调用完成块之前,它不会禁用按钮.相反,一旦动画制作完成,您应该重新启用它.
What you're doing is, you simply setting enabled on/off outside of the block. This is wrong, its executing once this method will call, thus its not disabling the button until completion block would call. Instead you should reenable it once your animation would get complete.
-(IBAction) buttonClick:(id)sender{
button.enabled = false;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
// code to execute
}
completion:^(BOOL finished){
// code to execute
button.enabled = true; //This is correct.
}];
//button.enabled = true; //This is wrong.
}
哦,是的,而不是 true
和 false
, YES
和 NO
看起来不错.:)
Oh and yes, instead of true
and false
, YES
and NO
would looks nice. :)