Scrolling with two fingers with a UIScrollView

后端 未结 14 643
长发绾君心
长发绾君心 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:09

    I put this in the viewDidLoad method and this accomplishes the scroll view handling the two touch pan behavior and another pan gesture handler handling the one touch pan behavior -->

    scrollView.panGestureRecognizer.minimumNumberOfTouches = 2
    
    let panGR = UIPanGestureRecognizer(target: self, action: #selector(ViewController.handlePan(_:)))
    panGR.minimumNumberOfTouches = 1
    panGR.maximumNumberOfTouches = 1
    
    scrollView.gestureRecognizers?.append(panGR)
    

    and in the handlePan method which is a function attached to the ViewController there is simply a print statement to verify that the method is being entered -->

    @IBAction func handlePan(_ sender: UIPanGestureRecognizer) {
        print("Entered handlePan numberOfTuoches: \(sender.numberOfTouches)")
    }
    

    HTH

提交回复
热议问题