且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iOS中防止同一UIButton上发生多个事件?

更新时间: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. :)