iOS 防止UIButton重复点击

 

使用UIButton的enabled或userInteractionEnabled

使用UIButton的enabled属性, 在点击后, 禁止UIButton的交互, 直到完成指定任务之后再将其enabled即可.

[btn addTarget:self action:@selector(nextStop:) forControlEvents:UIControlEventTouchUpInside];

 

- (void)nextStop:(UIButton *)sender {
    sender.enabled = NO;
    [self btnClicked];
}

 

- (void)btnClicked {

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    NSLog(@"btnClicked");
    btn.enabled = YES;
});
}

 

posted @ 2018-11-07 19:00  鸿鹄当高远  阅读(569)  评论(0编辑  收藏  举报