- 1.在 AppDelegate 中添加
[[UIButton appearance] setExclusiveTouch:YES];
- 2.
button.exclusiveTouch = YES;
- (void)buttonClicked:(id)sender {
//这里是关键,点击按钮后先取消之前的操作,再进行需要进行的操作
[[self class]cancelPreviousPerformRequestsWithTarget:self selector:@selector(buttonClicked:) object:sender];
[self performSelector:@selector(buttonClicked:) withObject:sender afterDelay:0.2f];
}
-(void)buttonClicked:(id)sender{
self.button.enabled =NO;
[selfperformSelector:@selector(changeButtonStatus)withObject:nilafterDelay:1.0f];//防止重复点击
}
-(void)changeButtonStatus{
self.button.enabled =YES;
}
- 3.使用 runtime,设置 n 秒内不会被重复点
- (1)导入 objc/runtime.h
- (2)创建 UIControl 或 UIButton 的分类