0

我正在创建自定义手势识别器。问题是从不调用重置方法,所以我无法重置识别器的状态。结果它只第一次工作

@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
4

2 回答 2

0

该文档指出:

在手势识别器状态设置为 UIGestureRecognizerStateEnded 或 UIGestureRecognizerStateRecognized 后,运行时调用此方法。

看来这就是你正在做的事情touchesEnded:。在此方法中放置一个断点并从那里获取它。

于 2012-10-25T12:12:59.237 回答
0

你必须把它写在你的 .h 文件中。

#import <UIKit/UIGestureRecognizerSubclass.h>
于 2014-05-14T12:25:17.310 回答