美文网首页
iOS防止重复点击

iOS防止重复点击

作者: C_JH | 来源:发表于2018-10-16 16:32 被阅读38次
    - 设置点击间隔时间
    - (void)viewEvent{
        static NSTimeInterval time = 0.0;
        NSTimeInterval currentTime = [NSDate date].timeIntervalSince1970;
        if (currentTime - time < 2.0) {
            NSLog(@"%s", __func__);
            return;
        }
        time = currentTime;
        
        //事件处理
    }
    
    - 点击后禁止交互事件
    - (void)viewEvent: (UIView *)view{
        view.userInteractionEnabled = NO;
        [self performSelector:@selector(viewStatusChange:) withObject:view afterDelay:2.0];
    
        //事件处理
    }
    
    - (void)viewStatusChange: (UIView *)view{
        view.userInteractionEnabled = YES;
    }
    
    - 点击后覆盖前一事件
    - (void)viewUserInterface: (UIView *)view{
        [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(viewEvent:) object:view];
        [self performSelector:@selector(viewEvent:) withObject:view afterDelay:.2];
    }
    
    - (void)viewEvent: (UIView *)view{
        //事件处理
    }
    

    相关文章

      网友评论

          本文标题:iOS防止重复点击

          本文链接:https://www.haomeiwen.com/subject/wymhzftx.html