单军华
2017-07-12 20d1260d26b028897f3c0935c12fc35aa37b2e93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
//  QKYDelayButton.m
//  qikeyun
//
//  Created by 马超 on 16/6/4.
//  Copyright © 2016年 Jerome. All rights reserved.
//
 
#import "QKYDelayButton.h"
 
static NSTimeInterval defaultDuration = 1.0f;
 
static BOOL _isIgnoreEvent = NO;
 
static void resetState() {
    
    _isIgnoreEvent = NO;
}
 
 
@implementation QKYDelayButton
 
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event
{
    if ([self isKindOfClass:[UIButton class]]) {
        
        self.clickDurationTime = self.clickDurationTime == 0 ? defaultDuration : self.clickDurationTime;
        
        if (_isIgnoreEvent) {
            
            return;
        }
        else if (self.clickDurationTime > 0) {
            
            _isIgnoreEvent = YES;
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.clickDurationTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                resetState();
            });
            
            [super sendAction:action to:target forEvent:event];
        }
    }
    else {
        
         [super sendAction:action to:target forEvent:event];
    }
}
 
@end