简体   繁体   中英

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. 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.

It seems that is what you are doing in touchesEnded: . Put a breakpoint in this method and take it from there.

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

#import <UIKit/UIGestureRecognizerSubclass.h>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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