简体   繁体   中英

ios gesture recognizer for all types

I just need to know if there is a way to catch all types of gestures in one instance UIGestureRecognizer.

Example: I have a UIView that I have to detect any type of tap made on it without creating an instance for each type of gesture

is there a way to do that ?

Thanks,

Off course it is, handle low level UIView events by yourself ( 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:

You can subclass the UIGestureRecognizer class and change its internal state to UIGestureRecognizerStateRecognized when touches begin.

Sample code:

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM