美文网首页
iOS长按手势调用两次

iOS长按手势调用两次

作者: JerryLMJ | 来源:发表于2016-01-07 14:14 被阅读3636次

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

主要原因是长按手势会分别在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
}

版权声明:出自MajorLMJ技术博客的原创作品 ,转载时必须注明出处及相应链接!

相关文章

  • iOS长按手势调用两次

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

  • iOS事件(二)手势

    iOS手势 轻拍手势UITapGestureRecognizer 长按手势UILongPressGestureRe...

  • 按钮长按事件

    iOS有长按手势UILongPressGestureRecognizer,这个手势需要指定长按的事件,指定时间之后...

  • Swift基础--手势识别(双击、捏、旋转、拖动、划动、长按)

    ==================================ios webView 同时添加单击和长按手势...

  • UIGestureRecognizer

    iOS 手势操作: 拖动,捏合,旋转,点按,长按,轻扫,自定义 UIGestureRecognizer 介绍 手势...

  • iOS 长按手势

    1、今天写图片浏览器的时候遇到了识别长按手势的判断 2、总体思路是在开始点击的时候启动一个定时器,设置时长,例如0...

  • 长按手势-iOS

  • iOS 手势

    本文介绍iOS开发中手势的运用,话不多说,先上代码;给tableView添加长按手势代码如下: 给cell添加长按...

  • IOS 长按手势触发两次事件

    在处理长按手势时,警告框一直弹出两次,解决方法如下: UILongPressGestureRecognizer*l...

  • 手势识别

    手势识别 6种手势识别 在iOS开发中有6中手势识别:点按、捏合、拖动、轻扫、旋转、长按苹果推出手势识别主要是为了...

网友评论

      本文标题:iOS长按手势调用两次

      本文链接:https://www.haomeiwen.com/subject/wkefkttx.html