适用于所有类型的ios手势识别器

时间:2013-03-13 08:27:51

标签: ios uigesturerecognizer

我只需要知道是否有办法在一个UIGestureRecognizer实例中捕获所有类型的手势。

示例:我有一个UIView,我必须检测任何类型的点击,而不为每种类型的手势创建一个实例

有办法吗?

谢谢,

2 个答案:

答案 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