@interface UIControl (XX)
@property (nonatomic, assign) NSTimeInterval time_Interval;
@end
static const char * Const_KEY = “time_Interval”;
static CFAbsoluteTime startTime,endTime;
@implementation UIControl (XX)
(void)load {
Method old = class_getInstanceMethod(self, @selector(sendAction:to:forEvent:));
Method new = class_getInstanceMethod(self, @selector(other_sendAction:to:forEvent:));
method_exchangeImplementations(old, new);
}(NSTimeInterval)time_Interval {
return [objc_getAssociatedObject(self, Const_KEY) doubleValue];
}(void)setTime_Interval:(NSTimeInterval)time_Interval {
objc_setAssociatedObject(self, Const_KEY, @(time_Interval), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}(void)other_sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event
{double diff = 0;
if (startTime == 0) {
startTime = CFAbsoluteTimeGetCurrent();
endTime = startTime;
}
else {
endTime = CFAbsoluteTimeGetCurrent();
diff = endTime - startTime;
startTime = endTime;
}if (diff > self.time_Interval)[self other_sendAction:action to:target forEvent:event];
}