Intercepting pan gestures over a UIScrollView breaks scrolling

后端 未结 3 1479
说谎
说谎 2020-12-13 12:48

I have a vertically-scrolling UIScrollView. I want to also handle horizontal pans on it, while allowing the default vertical scroll behavior. I\'ve put a transp

3条回答
  •  粉色の甜心
    2020-12-13 13:26

    Swift answer:

    let scrollViewPanGesture = UIPanGestureRecognizer(target: self, action: #selector(onPan(_:)))
    scrollViewPanGesture.delegate = self
    scrollView.addGestureRecognizer(scrollViewPanGesture)
    
    extension ViewController: UIGestureRecognizerDelegate {
        func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
            return true
        }
    }
    

提交回复
热议问题