zoukankan      html  css  js  c++  java
  • 按钮重复点击问题 UIbutton

    .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

  • 相关阅读:
    20162304 2017-2018-1 《程序设计与数据结构》第十周学习总结
    20162304 2017-2018-1 《程序设计与数据结构》第九周学习总结
    20162304 2017-2018-1 《程序设计与数据结构》第八周学习总结
    20162302 2017-2018-1《程序设计与数据结构》课程总结
    20162302 实验五《数据结构综合应用》实验报告
    20162302 实验四《图的实现与应用》实验报告
    20162302 《程序设计与数据结构》第十一周学习总结
    20162302 《程序设计与数据结构》第十周学习总结
    20162302 实验三《查找与排序》实验报告
    20162302 《程序设计与数据结构》第九周学习总结
  • 原文地址:https://www.cnblogs.com/daxueshan/p/7111258.html
Copyright © 2011-2022 走看看