zoukankan      html  css  js  c++  java
  • UIButton防止被重复点击

    一、避免屏幕内多个 UIButton 被重复点击

    • 1.在 AppDelegate 中添加[[UIButton appearance] setExclusiveTouch:YES];
    • 2.button.exclusiveTouch = YES;

    二、避免一个 UIButton 被多次点击

    • 1.在每次点击时先取消之前的操作
    - (void)buttonClicked:(id)sender {
    	//这里是关键,点击按钮后先取消之前的操作,再进行需要进行的操作
    	[[self class]cancelPreviousPerformRequestsWithTarget:self selector:@selector(buttonClicked:) object:sender];
    	[self performSelector:@selector(buttonClicked:) withObject:sender afterDelay:0.2f];
    }
    
    • 2.点击后设为不可被点击的状态,n 秒后恢复
    -(void)buttonClicked:(id)sender{
    	self.button.enabled =NO;
    	[selfperformSelector:@selector(changeButtonStatus)withObject:nilafterDelay:1.0f];//防止重复点击
    }
    
    -(void)changeButtonStatus{
    	self.button.enabled =YES;
    }
    
    • 3.使用 runtime,设置 n 秒内不会被重复点
      • (1)导入 objc/runtime.h
      • (2)创建 UIControl 或 UIButton 的分类
  • 相关阅读:
    Less(27a)GET
    Less(27)GET
    虚拟机打开文件黑屏
    mysql开放远程连接权限
    fidder如何设置代理转发
    如何获取APK的包名
    ADB调试原理之通俗版本
    adb端口5037被占用怎么办
    ADB调试原理
    如何使用无线调试手机
  • 原文地址:https://www.cnblogs.com/huilan/p/7299075.html
Copyright © 2011-2022 走看看