HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何防止iOS中同一个UIButton上的多个事件?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想防止在同一个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;
}

解决方法

你正在做的是,你只需在块外设置启用开/关.这是错误的,它执行一旦这个方法调用,因此它不会禁用按钮,直到完成块将调用.相反,一旦动画完成,你应该重新启用它.
-(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.
}

哦,是的,而不是真假,是和否看起来不错.

本图文内容来源于网友网络收集整理提供,作为学习参使用,版权属于原作者。

大佬总结

以上是大佬教程为你收集整理的如何防止iOS中同一个UIButton上的多个事件?全部内容,希望文章能够帮你解决如何防止iOS中同一个UIButton上的多个事件?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。