欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS 防止UIButton重复点击

程序员文章站 2023-10-15 18:02:42
使用UIButton的enabled或userInteractionEnabled 使用UIButton的enabled属性, 在点击后, 禁止UIButton的交互, 直到完成指定任务之后再将其enabled即可. [btn addTarget:self action:@selector(next ......

 

使用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;
});
}