cra*_*dev 8 touch uibutton ios
我希望防止连续多次点击UIButton.
我试过enabled和exclusiveTouch属性但它没有用.如:
-(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;
}
Run Code Online (Sandbox Code Playgroud)
Hem*_*ang 15
你正在做的是,你只需在块外设置启用开/关.这是错误的,它执行一旦这个方法将调用,因此它不会禁用按钮,直到完成块将调用.相反,一旦动画完成,你应该重新启用它.
-(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.
}
Run Code Online (Sandbox Code Playgroud)
哦,是的,而不是true和false,YES并且NO会看起来很好.:)