Disable 2 finger scrolling in UIScrollView

后端 未结 4 961
醉酒成梦
醉酒成梦 2021-02-02 11:44

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:



        
相关标签:
4条回答
  • 2021-02-02 12:22

    if you are using iOS SDK over 5.0, maybe you can use ui pan gesture recognizer directly.

    @property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
    
    ......
    
    [self.scrollView.panGestureRecognizer setMinimumNumberOfTouches:1];
    [self.scrollView.panGestureRecognizer setMaximumNumberOfTouches:1];
    
    0 讨论(0)
  • 2021-02-02 12:34

    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];
    
    0 讨论(0)
  • 2021-02-02 12:34

    I can confirm this is still an issue in iOS 8, but only when the UIPanGestureRecognizer is underlying a UIScrollView. Creating a UIView with a fresh UIPanGestureRecognizer and setting its maximumNumberOfTouches property works as expected.

    Submitted rdar://20890684 and copied to http://openradar.appspot.com/radar?id=6191825677189120. Please feel free to dupe.

    0 讨论(0)
  • 2021-02-02 12:43

    PROBLEM:

    When the UIPanGestureRecognizer is underlying a UIScrollView (which unfortunately does also effect UIPageViewController) the maximumNumberOfTouches is not behaving as expected - the minimumNumberOfTouches however always limits the lower end correctly.

    When monitoring these parameters they seem to do their job - it's just that UIScrollView doesn't honor them and ignores their values!


    REMEDY:

    You can find the solution in my answer to:

    UIScrollView scrolling only with one finger

    0 讨论(0)
提交回复
热议问题