简体   繁体   English

UIGestureRecognizer-永远不会调用重置

[英]UIGestureRecognizer - reset is never called

I'm creating custom gesture recognizer. 我正在创建自定义手势识别器。 The problem is that reset method is never called so I can't reset the state of recognizer. 问题在于,永远不会调用reset方法,因此我无法重置识别器的状态。 As result it works only for the first time 因此,它只能在第一次使用

@implementation TouchGestureRecognizer {

    UIGestureRecognizerState mState;
}

-(UIGestureRecognizerState) state {
    return mState;
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if( [touches count] == 1 ) {
        mState = UIGestureRecognizerStateBegan;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if( [touches count] == 1 ) {
        mState = UIGestureRecognizerStateChanged;
    }
}

- (void)reset {
    mState = UIGestureRecognizerStatePossible;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    mState = UIGestureRecognizerStateRecognized;
}

@end

The documentation states: 该文档指出:

The runtime calls this method after the gesture-recognizer state has been set to UIGestureRecognizerStateEnded or UIGestureRecognizerStateRecognized. 将手势识别器状态设置为UIGestureRecognizerStateEnded或UIGestureRecognizerStateRecognized后,运行时将调用此方法。

It seems that is what you are doing in touchesEnded: . 看来这就是您在touchesEnded:中所做的。 Put a breakpoint in this method and take it from there. 在此方法中放置一个断点,然后从那里获取它。

您必须将其写入.h文件中。

#import <UIKit/UIGestureRecognizerSubclass.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM