Reputation: 2955
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,
Upvotes: 3
Views: 2579
Reputation: 51
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
Upvotes: 3
Reputation: 7241
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:
Upvotes: 6