Note that there are some explanatory texts on larger screens.

plurals
  1. POUISwipeGestureRecognizer not working
    text
    copied!<p>I have a UIView inside of a UIScrollView, both created using IB. The UIView scrolls horizontally inside the UIScrollView. I want to detect left and right 2 finger swipes. </p> <p>Borrowing from the sample code I found in <a href="http://developer.apple.com/library/ios/#samplecode/SimpleGestureRecognizers/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40009460" rel="nofollow">SmpleGestureRecognizers</a>, I have put the following code in the viewDidLoad method of the UIScrollView's ViewController...</p> <pre><code>UIGestureRecognizer *recognizer; UISwipeGestureRecognizer *swipeRightRecognizer, *swipeLeftRecognizer; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; swipeRightRecognizer = (UISwipeGestureRecognizer *)recognizer; swipeRightRecognizer.numberOfTouchesRequired = 2; [self.view addGestureRecognizer:swipeRightRecognizer]; [recognizer release]; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer; swipeLeftRecognizer.numberOfTouchesRequired = 2; swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:swipeLeftRecognizer]; [recognizer release]; </code></pre> <p>I have set in the viewcontroller.h. and have the following delegate method...</p> <pre><code>- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { return YES; } </code></pre> <p>I am assuming this is a valid gestureRecognizer delegate method, but I cannot find any reference to it in the documentation.</p> <p>I do not get any errors but nothing happens when I do a 2 finger swipe. The delegate method is not called and neither is my action method. I tried removing the numbeOfTouchesRequired call to see if it might work with a single finger swipe to no avail.</p> <p>Am I adding the gestureRecognizers to the right view? I tried adding it to the UIView, the UIScrollView as well as self.view.superView. </p> <p>The sample code runs great. The only difference I can see between my implementation of the code and the sample code is the fact that I used IB to create the views and the sample code did not. I suspect that something is consuming the swipe gesture before it gets to my recognizers.</p> <p>What am I doing wrong.</p> <p>Thanks,</p> <p>John</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload