防止按钮多次点击

// 防止多次调用

#define kPreventRepeatClickTime(_seconds_) \

static BOOL shouldPrevent; \

if (shouldPrevent) return; \

shouldPrevent = YES; \

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((_seconds_) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ \

shouldPrevent = NO; \

});\

 

加入宏定义

然后下面的方式调用(在点击的按钮事件中,1秒允许点击一次):

-(void)doToolButtonClicked:(UIButton *)sender

{

    kPreventRepeatClickTime(1);

}

转载于:https://www.cnblogs.com/huangzs/p/11307965.html

你可能感兴趣的:(防止按钮多次点击)