• 如何增加按钮的点击间隔时间


    也是写一个分类

    #import <UIKit/UIKit.h>

     

    @interface UIControl (FMGControl)

    @property (assign, nonatomic) NSTimeInterval   acceptEventInterval;

     

    @end

     

     

    ---------------下面是.m文件---------------------

    #import "UIControl+FMGControl.h"

    #import <objc/runtime.h>

    static const char *UIControl_acceptEventInterval = "UIControl_acceptEventInterval";

     

    @implementation UIControl (FMGControl)

    - (NSTimeInterval)acceptEventInterval

    {

        return [objc_getAssociatedObject(self, UIControl_acceptEventInterval) doubleValue];

    }

     

     

    - (void)setAcceptEventInterval:(NSTimeInterval)acceptEventInterval

    {

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

    }

     

    - (BOOL)FMG_ignoreEvent

    {

        return [objc_getAssociatedObject(self, UIControl_acceptEventInterval) doubleValue];

    }

     

    + (void)load

    {

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

        Method b = class_getInstanceMethod(self, @selector(FMG_sendAction:to:froEvent:));

        

        method_exchangeImplementations(a, b);

    }

     

    - (void)FMG_sendAction:(SEL)action to:(id)target froEvent:(UIEvent *)event

    {

        if (self.acceptEventInterval > 0) {

            if (self.userInteractionEnabled) {

                

                [self FMG_sendAction:action to:target froEvent:event];

            }

            self.userInteractionEnabled = NO;

            

            [self performSelector:@selector(setUserInteractionEnabled:) withObject:@(YES) afterDelay:self.acceptEventInterval];

            

            

            // GCD 延迟执行 self.acceptEventInterval:为延迟时间

            __weak typeof (self) weakSelf = self;

            dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.acceptEventInterval * NSEC_PER_SEC));

            

            dispatch_after(delayTime, dispatch_get_main_queue(), ^{

                weakSelf.userInteractionEnabled = YES;

            });

            

            

            

        } else {

            [self FMG_sendAction:action to:target froEvent:event];

        }

        

    }

     

    @end

     

    使用时:

      

    self.ViewButton.acceptEventInterval=5;//间隔5秒才能点击

  • 相关阅读:
    devops之 gitlab-ci + mesos + docker + marathon 持续发布③marathon常用api的使用
    centos7环境下二进制编译安装ffmpeg
    jenkins2.236 + sonarqube7.6 + sonar-scanner3.3的集成配置和生产环境使用示例
    zabbix添加top10内存和cpu资源占用情况
    Marathon基于有认证的harbor仓库创建应用
    devops之 gitlab-ci + mesos + docker + marathon 持续发布③marathon 结合 gitlab-ci的CICD持续发布
    docker拉取指定版本的centos和python镜像
    devops之 gitlab-ci + mesos + docker + marathon 持续发布②安装marathon
    devops之 gitlab-ci + mesos + docker + marathon 持续发布①mesos集群环境的搭建
    zabbix4.0监控gpu
  • 原文地址:https://www.cnblogs.com/dashengios/p/10513343.html
Copyright © 2020-2023  润新知