码迷,mamicode.com
首页 > 其他好文 > 详细

按钮重复点击问题 UIbutton

时间:2017-07-03 16:19:47      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:ping   import   object   char   property   res   turn   ace   重复   

.h

#import <UIKit/UIKit.h>

#import <objc/runtime.h>

@interface UIControl (XY)

 

@property (nonatomic, assign) NSTimeInterval fy_acceptEventInterval;

@property (nonatomic, assign) BOOL fy_ignoreEvent;

 

@end

 

.m

//

//  UIControl+XY.m

//  Test

//

//  Created by xueshan on 17/7/3.

//  Copyright ? 2017 xueshan. All rights reserved.

//

 

#import "UIControl+XY.h"

 

@implementation UIControl (XY)

 

static const char *UIControl_acceptEventInterval = "UIControl_acceptEventInterval";

static const char *UIControl_ignoreEvent = "UIControl_ignoreEvent";

 

- (NSTimeInterval)fy_acceptEventInterval{

    return [objc_getAssociatedObject(self, UIControl_acceptEventInterval) doubleValue];

}

- (void)setFy_acceptEventInterval:(NSTimeInterval)fy_acceptEventInterval{

    objc_setAssociatedObject(self, UIControl_acceptEventInterval, @(fy_acceptEventInterval), OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

 

- (BOOL)fy_ignoreEvent{

    return [objc_getAssociatedObject(self, UIControl_ignoreEvent) boolValue];

}

 

- (void)setFy_ignoreEvent:(BOOL)fy_ignoreEvent{

    objc_setAssociatedObject(self, UIControl_ignoreEvent, @(fy_ignoreEvent), OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

 

+ (void)load{

    Method a = class_getInstanceMethod(self, @selector(sendAction:to:forEvent:));

    Method b = class_getInstanceMethod(self, @selector(_fy_sendAction:to:forEvent:));

    method_exchangeImplementations(a, b);

}

 

- (void)_fy_sendAction:(SEL)selector to:(id)target forEvent:(UIEvent*)event{

    if (self.fy_ignoreEvent) return;

    

    if (self.fy_acceptEventInterval > 0) {

        self.fy_ignoreEvent = YES;

        [self performSelector:@selector(setFy_ignoreEvent:) withObject:@(NO) afterDelay:self.fy_acceptEventInterval];

    }

    

    [self _fy_sendAction:selector to:target forEvent:event];

}

 

@end

按钮重复点击问题 UIbutton

标签:ping   import   object   char   property   res   turn   ace   重复   

原文地址:http://www.cnblogs.com/daxueshan/p/7111258.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!