Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable 2 finger scrolling in UIScrollView

Tags:

I'd like to disable two-finger scrolling in my UIScrollView.
I subclassed it and tweaked its built-in gesture recognizers with the following code:

for (UIGestureRecognizer *mgestureRecognizer in scroller.gestureRecognizers) {     
    if ([mgestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
    {
        UIPanGestureRecognizer *mpanGR = (UIPanGestureRecognizer *) mgestureRecognizer;
        mpanGR.minimumNumberOfTouches = 1; 
        mpanGR.maximumNumberOfTouches = 1;

    }

    if ([mgestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]])
    {
        UISwipeGestureRecognizer *mswipeGR = (UISwipeGestureRecognizer *) mgestureRecognizer;
        mswipeGR.numberOfTouchesRequired = 1;
    }

For some reason, maximumNumberOfTouches does not seem to work. I can still scroll with one or two fingers. If I change both properties to 2, I can successfully disable one-finger scrolling and require two touches.

Any ideas?

like image 225
stipoy Avatar asked Nov 21 '11 10:11

stipoy


1 Answers

I realize this is an old thread, but it took me a long time to figure this out, so I thought I would share. Here's what I did to disable two-finger scrolling:

// set up a two-finger pan recognizer as a dummy to steal two-finger scrolls from the scroll view
// we initialize without a target or action because we don't want the two-finger pan to be handled
UIPanGestureRecognizer *twoFingerPan = [[UIPanGestureRecognizer alloc] init];
twoFingerPan.minimumNumberOfTouches = 2;
twoFingerPan.maximumNumberOfTouches = 2;
[scrollView addGestureRecognizer:twoFingerPan];
like image 145
Jake Stoeffler Avatar answered Sep 17 '22 15:09

Jake Stoeffler