我只需要知道是否有办法在一个UIGestureRecognizer实例中捕获所有类型的手势。
示例:我有一个UIView,我必须检测任何类型的点击,而不为每种类型的手势创建一个实例
有办法吗?
谢谢,
答案 0 :(得分:6)
当然是,自己处理低级别的UIView事件(Event Handling Guide for iOS):
Responding to Touch Events
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
Responding to Motion Events
– motionBegan:withEvent:
– motionEnded:withEvent:
– motionCancelled:withEvent:
答案 1 :(得分:3)
您可以继承UIGestureRecognizer
类,并在触摸开始时将其内部状态更改为UIGestureRecognizerStateRecognized
。
示例代码:
@interface UITouchGestureRecognizer : UIGestureRecognizer
@end
#import <UIKit/UIGestureRecognizerSubclass.h>
@implementation UITouchGestureRecognizer
- (void) reset
{
[super reset];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
self.state = UIGestureRecognizerStateRecognized;
}
@end