Scrolling with two fingers with a UIScrollView

后端 未结 14 637
长发绾君心
长发绾君心 2020-11-29 21:29

I have an app where my main view accepts both touchesBegan and touchesMoved, and therefore takes in single finger touches, and drags. I want to im

14条回答
  •  被撕碎了的回忆
    2020-11-29 22:12

    This answers are a mess since you can only find the correct answer by reading all the other answers and the comments (closest answer got the question backwards). The accepted answer is too vague to be useful, and suggests a different method.

    Synthesizing, this works

        // makes it so that only two finger scrolls go
        for (id gestureRecognizer in self.gestureRecognizers) {     
            if ([gestureRecognizer  isKindOfClass:[UIPanGestureRecognizer class]])
            {
                UIPanGestureRecognizer *panGR = gestureRecognizer;
                panGR.minimumNumberOfTouches = 2;              
                panGR.maximumNumberOfTouches = 2;
            }
        }   
    

    This requires two fingers for a scroll. I've done this in a subclass, but if not, just replace self.gestureRecognizers with myScrollView.gestureRecognizers and you're good to go.

    The only thing that I added is using id to avoid an ugly cast :)

    This works but can get quite messy if you want your UIScrollView to do zoom too... the gestures don't work correctly, since pinch-to-zoom and scroll fight it out. I'll update this if I find a suitable answer.

提交回复
热议问题