由于以前没有很细致的研究过长按手势,所以今天使用的时候发现长按手势会调用两次响应事件。

主要原因是长按手势会分别在UIGestureRecognizerStateBeganUIGestureRecognizerStateEnded状态时调用响应函数

这时就需要在响应事件中增加手势状态的判断,根据具体的应用情况在相应的状态中执行操作。

typedefNS_ENUM(NSInteger, UIGestureRecognizerState) {
UIGestureRecognizerStatePossible,// the recognizer has not yet recognized its gesture, but may be evaluating touch events. this is the default state
UIGestureRecognizerStateBegan,// the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop
UIGestureRecognizerStateChanged,// the recognizer has received touches recognized as a change to the gesture. the action method will be called at the next turn of the run loop
UIGestureRecognizerStateEnded,// the recognizer has received touches recognized as the end of the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible
UIGestureRecognizerStateCancelled,// the recognizer has received touches resulting in the cancellation of the gesture. the action method will be called at the next turn of the run loop. the recognizer will be reset to UIGestureRecognizerStatePossible
UIGestureRecognizerStateFailed,// the recognizer has received a touch sequence that can not be recognized as the gesture. the action method will not be called and the recognizer will be reset to UIGestureRecognizerStatePossible
// Discrete Gestures – gesture recognizers that recognize a discrete event but do not report changes (for example, a tap) do not transition through the Began and Changed states and can not fail or be cancelled
UIGestureRecognizerStateRecognized =UIGestureRecognizerStateEnded// the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible
};
if (longPressGesture.state == UIGestureRecognizerStateBegan) {
// do something
}else if (longPressGesture.state == UIGestureRecognizerStateEnded){
// do something
}

最新文章

  1. 实用的Scala泛函编程
  2. C++类编程(一)const的使用
  3. 【iHMI43 4.3寸液晶模块】demo例程(版本1.02)发布
  4. leetcode 112 Path Sum ----- java
  5. PC问题-使用BAT方法设置IP地址
  6. Chinese_PRC_CI_AS and SQL_Latin1_General_CP1_CI_AS类型错误
  7. IOS Main函数
  8. 通过浏览器直接打开Android应用程序
  9. MacOS + Linux + Nginx
  10. 【C语言探险】 第四课的第二部分:串
  11. Directx11学习笔记【一】 最简单的windows程序HelloWin
  12. 201521123112《Java程序设计》第13周学习总结
  13. 解读Scrum燃尽图
  14. 【编程开发】PHP---面向对象
  15. Google Bigtable (中文版)
  16. 在表单提交之前做校验-利用jQuery的submit方法
  17. 突击战 (uva 11729)贪心
  18. [Swift]LeetCode304. 二维区域和检索 - 矩阵不可变 | Range Sum Query 2D - Immutable
  19. [原]Jenkins(十九) jenkins再出发之jenkins邮件通知
  20. 【ocp-12c】最新Oracle OCP-071考试题库(46题)

热门文章

  1. 洛谷 U3348 A2-回文数
  2. setup命令
  3. Winform C# 编程 1
  4. UVA 10891 Game of Sum (决策优化)
  5. codeforce Gym 100500F Door Lock (二分)
  6. iOS 微信和支付宝关于回调处理
  7. ansible 任务委派 delegate_to
  8. Predicate和Consumer接口的使用
  9. Vue中使用computed与watch结合实现数据变化监听
  10. Problem C: 查找最大元素