Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: Cancel UIScrollView touches when using 2 fingers
    primarykey
    data
    text
    <p>I have written a UIScrollView subclass that I am using to scroll a series of UITableViews. See the following diagram:</p> <p><img src="https://i.stack.imgur.com/PEE4a.png" alt="enter image description here"></p> <p>As you can see I have several vertically scrolling UITableViews, that are being scrolled horizontally inside a parent UIScrollView. This all works fine. However the application has a number of <em>global</em> gestures. For example, if I swipe in a given direction with 2 fingers, I do a UIView transition to another part of the app. but if I do the gesture on top of the scroll view and/or its child table views, they naturally scroll their content. This doesn't look good and causes some layout issues.</p> <p>What I would like to figure out is how to disable all scrolling, on both the UIScrollView and its child UITableViews, when a user touches <em>anywhere</em> with two fingers, and only with two fingers. I've tried variations of overriding touchesBegan, touchesEnded, touchesShouldCancel etc... but I can't get it quite right. Any help is much appreciated.</p> <p>Here is my gesture handling code:</p> <pre><code>UISwipeGestureRecognizer *twoFingerSwipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerSwipe:)]; [twoFingerSwipeUp setNumberOfTouchesRequired:2]; [twoFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp]; [twoFingerSwipeUp setDelegate:self]; // 'self' is the superview of the UIScrollView, which is a UIView. [self addGestureRecognizer:twoFingerSwipeUp]; [twoFingerSwipeUp release]; // ... repeat the above code for up, down, left, right gestures ... - (void)handleTwoFingerSwipe:(UISwipeGestureRecognizer*)swipeGesture { switch ([swipeGesture direction]) { case UISwipeGestureRecognizerDirectionUp: [self changeToView:viewAbove]; break; case UISwipeGestureRecognizerDirectionDown: [self changeToView:viewBelow]; break; case UISwipeGestureRecognizerDirectionRight: [self changeToView:viewToTheRight]; break; case UISwipeGestureRecognizerDirectionLeft: [self changeToView:viewToTheLeft]; break; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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