2013-03-13 39 views
3

我只需要知道是否有辦法在一個實例UIGestureRecognizer中捕捉所有類型的手勢。所有類型的ios手勢識別器

例子:我有一個UIView,我必須以檢測它使任何類型的水龍頭沒有爲每種類型的手勢

的創建一個實例是有辦法做到這一點?

感謝,

回答

6

當然,它是由你自己(Event Handling Guide for iOS)處理低級別的UIView事件:

Responding to Touch Events 
– touchesBegan:withEvent: 
– touchesMoved:withEvent: 
– touchesEnded:withEvent: 
– touchesCancelled:withEvent: 
Responding to Motion Events 
– motionBegan:withEvent: 
– motionEnded:withEvent: 
– motionCancelled:withEvent: 
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