UILongPressGestureRecognizer的selector多次调用解决方法
2024-10-08 09:15:54
当你使用longPress gesture recognizer 时,你可能会发现调用了多次。
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
longPress.delegate = self;
[self.view addGestureRecognizer:longPress];
其实时因为响应不同的状态。所以,要在你的方法里加上状态的判断。可以看到,开始响应,结束响应,如果你不判断的话,都会调用你的方法。
- (void)longPress:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
[self yourMethod];
}
}
最新文章
- 30. PL/SQL Developer连接服务器查询时,数据乱码处理
- threeSum_0
- hdu 3549 Flow Problem
- Scala学习——数组/映射/元组
- UVA 10537 The Toll! Revisited 过路费(最短路,经典变形)
- Bootstrap_Javascript_滚动监视器
- 为应用程序的选项卡及ActionBar设置样式
- I can do it
- [Swift]LeetCode919. 完全二叉树插入器 | Complete Binary Tree Inserter
- iframe父页面与子页面赋值
- js 小写金额转大写
- PyCharm 如何新建Django工程项目
- falsk简单项目示例
- 使用Swagger2时遇到的问题
- Codeforces-gym-101020 problem C. Rectangles
- idhttp与cookie
- 定制FileField中的上传文件名称
- (转)Spring Cloud(二)
- centos7 虚拟机安装docker-ce-17.09
- 不用中间变量交换a 和b的值
热门文章
- jqGrid简单介绍
- eclipse报错 com/genuitec/eclipse/j2eedt/core/J2EEProjectUtil 转
- VS 2010不显示头文件源文件和所有以前分类的文件夹,*.h 和*.cpp都显示在同一个文件
- java基础(五)
- iOS设备保持横排方向
- 《Linear Algebra and Its Applications》-chaper6-正交性和最小二乘法-基本概念与定理
- zoj 3757 Alice and Bob and Cue Sports 月赛A 模拟
- Nginx系列~负载均衡服务器与WWW服务器的实现
- 一款很不错的html转xml工具-Html Agility Pack
- zoj 3657 策略题 easy