Detect direction of UIScrollView scroll in scrollViewWillBeginDragging

后端 未结 9 1826
心在旅途
心在旅途 2020-12-17 09:30

I did google enough, & I did check posts like these ( Finding the direction of scrolling in a UIScrollView? ) in stackoverflow before posting this. I have a dynamic numb

9条回答
  •  佛祖请我去吃肉
    2020-12-17 09:50

    Swift 3 Solution

    1- Add UIScrollViewDelegate

    2- Add this code

    func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
        let actualPosition = scrollView.panGestureRecognizer.translation(in: scrollView.superview)
        if (actualPosition.y > 0){
            // Dragging down
        }else{
            // Dragging up
        }
    }
    

提交回复
热议问题