我正在创建自定义手势识别器。问题是永远不会调用reset方法,所以我无法重置识别器的状态。因此,它仅适用于第一次
@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
答案 0 :(得分:0)
文档说明:
运行时在手势识别器状态设置为UIGestureRecognizerStateEnded或UIGestureRecognizerStateRecognized后调用此方法。
这似乎就是你在touchesEnded:
中所做的。在这个方法中加一个断点并从那里拿走它。
答案 1 :(得分:0)
你必须在你的.h文件中写这个。
#import <UIKit/UIGestureRecognizerSubclass.h>