最繁琐的一种方法是(给按钮加判断):

//  Created by Mini on 16/3/11.
//  Copyright © 2016年 IZHUO.NET. All rights reserved.
//#import "ViewController.h"@interface ViewController ()@property (nonatomic,strong,readonly) UIButton *firstButton;
@property (nonatomic,strong,readonly) UIButton *secondButton;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];//为第一个button添加事件_firstButton = [UIButton buttonWithType:UIButtonTypeCustom];[_firstButton addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];[_firstButton addTarget:self action:@selector(recordButtonAction:) forControlEvents:UIControlEventTouchUpInside];[_firstButton addTarget:self action:@selector(recoveryButtonAction:) forControlEvents:UIControlEventTouchUpInside];//为第二个button添加事件_secondButton = [UIButton buttonWithType:UIButtonTypeCustom];[_secondButton addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];[_secondButton addTarget:self action:@selector(recordButtonAction:) forControlEvents:UIControlEventTouchUpInside];[_secondButton addTarget:self action:@selector(recoveryButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark -- 事件响应
//点击按钮到离开屏幕响应事件时恢复按钮的状态并触发事件
- (void)actionButton:(UIButton *)sender {_firstButton.enabled = YES;_secondButton.enabled = YES;if (sender == _firstButton) {[self firstButtonPressed];}else if (sender == _secondButton) {[self secondButtonPressed];}
}// 当按钮点下时把另一按钮设置不可点
- (void)recordButtonAction:(UIButton *)sender {if (sender == _firstButton) {_secondButton.enabled = NO;}else if (sender == _secondButton) {_secondButton.enabled = NO;}
}
//当点下按钮从按钮区域外离开时恢复button状态
- (void)recoveryButtonAction:(UIButton *)sender {_firstButton.enabled = YES;_secondButton.enabled = YES;
}- (void)firstButtonPressed {//第一个按钮事件处理
}
- (void)secondButtonPressed {//第二个按钮事件处理
}

最简单一种方法是:
[_firstButton setExclusiveTouch:YES];
[_secondButton setExclusiveTouch:YES];
这个是UIView的成员方法, 只要是继承自UIView的控件都可以用。

iOS开发两个距离较近的按钮同时触发事件的解决方法相关推荐

  1. ios开发学习中遇到问题[LayoutConstraints] Unable to simultaneously satisfy constraints.的解决方法

    这个问题是在纯代码创建一个登录界面时,点击第二个文本框时弹出的,也不报错,就是弹出一大堆信息,之前都是用storyboard拖的控件和设置一些属性,用纯代码还不太会,所以会弄出很多问题. 这个问题网上 ...

  2. iOS开发用Eventkit向日历和提醒事项中加入事件和闹铃

    iOS开发用Eventkit向日历和提醒事项中加入事件和闹铃 直接上代码说明如何使用,后面有详细的介绍 主要使用Eventkit事件库的EKEventStore类 该类负责日历和提醒事件的管理,可以简 ...

  3. IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法

    在 IOS 开发当中经常碰到 whose view is not in the window hierarchy 的错误,该错误简单的说,是由于 "ViewController" ...

  4. Mint-ui中loadmore(上拉加载下拉刷新)组件在ios中滑动会触发点击事件的解决方法...

    bug说明: Mint-ui中loadmore(上拉加载下拉刷新)组件 在 使用fastclick的情况下 ,在ios设备中滑动会触发点击事件: 解决方法: 我是按需引入,去项目中找到loadmore ...

  5. 开发chrome 插件, background.js中 console log 看不到解决方法

    开发chrome 插件, background.js中 console log 看不到解决方法 参考文章: (1)开发chrome 插件, background.js中 console log 看不到 ...

  6. IOS 浏览器端overflow:scroll overflow:auto元素无法滑动bug解决方法整理

    导致 iframe 里面的内容会把我下面的两个按钮一直怼到最下面,加载的时候按钮是有的 等到 iframe 里的内容加载完成后 那两个按钮就不显示了 解决方法: 由于我在iframe 标签外加了的di ...

  7. 微信开发学习 问题1: 网页授权问题 “该连接无法访问” 解决方法

    微信开发学习 问题1: 网页授权问题 "该连接无法访问" 解决方法 参考文章: (1)微信开发学习 问题1: 网页授权问题 "该连接无法访问" 解决方法 (2) ...

  8. iOS中 H5的input输入框focus()无法自动拉起键盘(解决方法)

    iOS中 H5的input输入框focus()无法自动拉起键盘(解决方法) 参考文章: (1)iOS中 H5的input输入框focus()无法自动拉起键盘(解决方法) (2)https://www. ...

  9. JS IOS/iPhone的Safari浏览器不兼容Javascript中的Date()问题的解决方法

    JS IOS/iPhone的Safari浏览器不兼容Javascript中的Date()问题的解决方法 参考文章: (1)JS IOS/iPhone的Safari浏览器不兼容Javascript中的D ...

最新文章

  1. 基于相交线的双目平面SLAM
  2. vim win装_VIM的代码补全工具YouCompleteMe在Windows上的安装攻略
  3. 2.FastJson公司--阿里巴巴开源的速度最快的Json和对象转换工具
  4. 【机器视觉】 endtry算子
  5. Effective Java之在公有类中使用访问方法而非公有域(十四)
  6. 三种方式让你轻松监控 EntityFramework 中的 sql 流转
  7. TensorFlow 三岁了,你想对它说点什么?
  8. 三星上线售价99万8K电视 网友:是不是多打了一位数
  9. udt编写高性能服务器,基于UDT协议的Oracle数据库远程备份的设计和实现
  10. php把数据表格数据,php怎样把数据添加到数据表
  11. 输出英文字母java数组_JAVA语言之通过生成随机数组来转化为字母进行输出的类...
  12. JavaScript实现(轮播图,随机数,抽名字游戏,广告循环文字)
  13. 使用Monkey做一次APP的压力测试
  14. 郭天祥10天学会单片机笔记学习资料(1.1)
  15. 小程序 订阅消息 原来就是如此
  16. one 主格 复数 宾格_主格和宾格的复数形式到底怎么写请说出答案
  17. android 隐藏文本,Android使用facebook隐藏库加密plaint文本
  18. Javascript 合集 自己整理的收藏 记录一下(最下面有惊喜)
  19. QImage 图像格式小结,QImage::Format
  20. 学习笔记:Towards Counterfactual Image Manipulation via CLIP 基于CLIP的反事实图像处理研究

热门文章

  1. Robot Framework--环境搭建
  2. 并不对劲的bzoj2038:p1494:[国家集训队]小Z的袜子
  3. 文件上传优化CommonsMultipartResolver
  4. [D3D] - 用PerfHUD来调试商业游戏
  5. Java创建cookie和删除cookie
  6. 华为手机充满有提醒吗_华为推出的联发科天玑手机华为nova8 SE,你会买吗?
  7. 怎么固定串口号_工业交换机的背板带宽怎么计算?
  8. 电脑没有ps怎么改照片dpi_PS入门的小技巧来啦!小白们还在等什么呢?快进来啊!...
  9. V8 Promise源码全面解读
  10. linux设备和驱动注册,Linux驱动第五篇-----驱动注册和生成设备节点