iOS手势识别初探

来源:互联网 发布:自古黑金无he 知乎 编辑:程序博客网 时间:2024/04/29 12:01

UIGestureRecognizerState的定义如下:

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 becalled at the next turn of the run loop

    UIGestureRecognizerStateChanged,    // the recognizer has received touches recognized as a change to the gesture. the actionmethod 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

};


UIGestureRecognizerStatePossible
默认状态,手势识别器尚未识别出手势,但是可能已经在处理触屏事件了。
UIGestureRecognizerStateBegan
手势识别器识别出了手势,接下来将会执行action方法。
UIGestureRecognizerStateChanged
手势识别器识别出了手势的改变,接下来将会执行action方法。
UIGestureRecognizerStateEnded
手势结束状态
UIGestureRecognizerStateCancelled
手势撤销
UIGestureRecognizerStateFailed
无法识别
UIGestureRecognizerStateRecognized
已经识别手势,接下来置为默认状态。

原创粉丝点击