// 防止多次调用 #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); } |