Simultaneous gesture recognizers in Iphone SDK

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:)]; … Read more

Does UIGestureRecognizer work on a UIWebView?

From what I have seen, UIWebView does not play well with others. For gesture recognizers, you could try returning YES from: – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer; I had to be backwards compatible with 3.0 so I ended up doing all the gesture handling with Javascript inside the UIWebView. Not a good solution, but it worked … Read more

UIPageViewController Gesture recognizers

Here is another solution, which can be added in the viewDidLoad template right after the self.view.gestureRecognizers = self.pageViewController.gestureRecognizers part from the Xcode template. It avoids messing with the guts of the gesture recognizers or dealing with its delegates. It just removes the tap gesture recognizer from the views, leaving only the swipe recognizer. self.view.gestureRecognizers = … Read more

UITapGestureRecognizer – single tap and double tap

UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSingleTap)] autorelease]; singleTap.numberOfTapsRequired = 1; [self.view addGestureRecognizer:singleTap]; UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doDoubleTap)] autorelease]; doubleTap.numberOfTapsRequired = 2; [self.view addGestureRecognizer:doubleTap]; [singleTap requireGestureRecognizerToFail:doubleTap]; Note: If you are using numberOfTouchesRequired it has to be .numberOfTouchesRequired = 1; For Swift let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(didPressPartButton)) singleTapGesture.numberOfTapsRequired = 1 view.addGestureRecognizer(singleTapGesture) let … Read more

How do I Disable the swipe gesture of UIPageViewController?

The documented way to prevent the UIPageViewController from scrolling is to not assign the dataSource property. If you assign the data source it will move into ‘gesture-based’ navigation mode which is what you’re trying to prevent. Without a data source you manually provide view controllers when you want to with setViewControllers:direction:animated:completion method and it will … Read more

Gesture recognizer and button actions

In the “shouldReceiveTouch” method you should add a condition that will return NO if the touch is in the button. This is from apple SimpleGestureRecognizers example. – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { // Disallow recognition of tap gestures in the segmented control. if ((touch.view == yourButton)) {//change it to your condition return NO; } return … Read more

UILongPressGestureRecognizer gets called twice when pressing down

UILongPressGestureRecognizer is a continuous event recognizer. You have to look at the state to see if this is the start, middle or end of the event and act accordingly. i.e. you can throw away all events after the start, or only look at movement as you need. From the Class Reference: Long-press gestures are continuous. … Read more

Can you attach a UIGestureRecognizer to multiple views?

A UIGestureRecognizer is to be used with a single view. I agree the documentation is spotty. That UIGestureRecognizer has a single view property gives it away: view The view the gesture recognizer is attached to. (read-only) @property(nonatomic, readonly) UIView *view Discussion You attach (or add) a gesture recognizer to a UIView object using the addGestureRecognizer: … Read more