Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simultaneous gesture recognizers in Iphone SDK

I need to catch two different swipping gestures using UISwipeGestureRecognizer(for example, UISwipeGestureRecognizerDirectionRight and UISwipeGestureRecognizerDirectionLeft). When I add two different recognisers with addGestureRecognizer method, only last added recognizer works. I've read that I need to implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method of UIGestureRecognizerDelegate protocol, but nothing works.

Can anyone help with simple example of catching two or more same gestures? Thanks!

like image 955
user294890 Avatar asked Apr 13 '10 08:04

user294890


People also ask

How do I add swipe gestures in iOS?

Add four swipe gesture recognizers to your view. Set each one with the target direction from the attribute inspector. You can select right, left, up or down. One by one, select the swipe gesture recognizer, control + drag to your view controller.

What is Pan gesture in iOS?

A pan gesture occurs any time the user moves one or more fingers around the screen. A screen-edge pan gesture is a specialized pan gesture that originates from the edge of the screen. Use the UIPanGestureRecognizer class for pan gestures and the UIScreenEdgePanGestureRecognizer class for screen-edge pan gestures.

How many types of gestures are there in iOS?

There are seven type of gesture that support in ios .

What is Cancelstouchesinview?

A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.


1 Answers

It was really easy:

At first we should create class, that implements UIGestureRecognizerDelegate protocol:

@interface MyGestureDelegate : NSObject <UIGestureRecognizerDelegate> 
  @implementation MyGestureDelegate  - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{     return YES; }  - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{     return YES; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{     return YES; }  

And use it like this:

      UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc]                                               initWithTarget:self action:@selector(handleSwipeGestureLeft:)];     [self.view addGestureRecognizer:swipeGestureLeft];     swipeGestureLeft.direction = UISwipeGestureRecognizerDirectionLeft;     [swipeGestureLeft release];      UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]                                           initWithTarget:self action:@selector(handleSwipeGesture:)];     swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;     [self.view addGestureRecognizer:swipeGesture];      MyGestureDelegate *deleg = [[MyGestureDelegate alloc] init];      [swipeGesture setDelegate:deleg];     [swipeGesture release];  

like image 64
user294890 Avatar answered Sep 22 '22 00:09

user294890