zoukankan      html  css  js  c++  java
  • iOS长按手势调用两次解决方法

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

    主要原因是长按手势会分别在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
    }
  • 相关阅读:
    【转载】比较c++中的值传递,引用传递,指针传递
    【转载】在ARX中通过COM在ACAD中添加菜单和工具条
    【转载】预编译头文件phc
    jsp 连 sql server
    今天上传点关于asp的好东东
    转: [软件人生]给一个刚毕业学生朋友的建议
    世界首富比尔盖茨花钱全过程
    wap开发工具
    一名25岁的董事长给大学生的18条忠告
    今天再来点好东东,
  • 原文地址:https://www.cnblogs.com/ming1025/p/6139842.html
Copyright © 2011-2022 走看看