我正在嘗試爲我的視圖創建自定義手勢識別器。我在這裏提到這個答案:但由於某種原因,被觸及的結束,也觸及movied沒有得到調用。只有接觸開始被調用。觸摸使用UIGestureRecogniser進行子類化時未結束調用
子類:
#import "TapGesture.h"
#import <UIKit/UIGestureRecognizerSubclass.h>
@implementation TapGesture
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if (self.state == UIGestureRecognizerStatePossible) {
self.state = UIGestureRecognizerStateRecognized;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
self.state = UIGestureRecognizerStateFailed;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
self.state = UIGestureRecognizerStateFailed;
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
}
@end
,我初始化的TapGesture如下:
TapGesture *tapGesture=[[TapGesture alloc]initWithTarget:self action:@selector(incrementValue)];
tapGesture.delaysTouchesEnded=NO;
tapGesture.cancelsTouchesInView=NO;
[_workButton addGestureRecognizer:tapGesture]; //_workButton is a UIView
我不; t有視圖中的任何其他手勢識別器。如果我在UIView中使用相同的方法,所有這些都按預期方式調用。
爲什麼touchesEnded/touchesMoved在UIGestureRecogniser類中重寫時沒有被調用?