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

  • 相关阅读:
    第一节:理解垃圾回收平台的基本工作原理
    回想笔记 瞎比比 域名注册 解析绑定ip 下载证书 设置证书 重定向http到https请求
    flask 设置https请求 访问flask服务器
    关于 服务器ip和域名进行一个绑定
    ubuntu 安装flask+nginx+gunicorn 待定
    使用flask-dropzone 上传图片文件
    flask 对于用户登录保持状态 flask_login
    flask 对于邮件url进行一个加密防止爆破
    flask 密码加密 视频资料
    flask 多线程邮件异步发送 视频资料
  • 原文地址:https://www.cnblogs.com/daxueshan/p/7111258.html
Copyright © 2011-2022 走看看