Detect direction of UIScrollView scroll in scrollViewWillBeginDragging

后端 未结 9 1819
心在旅途
心在旅途 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 10:00

    There seem to be issues with detecting scroll direction based on the translation of the scrollView's pan recognizer in iOS 7+. This seems to be working pretty seamlessly for my purposes

    func scrollViewDidScroll(scrollView: UIScrollView) {
        if !scrollDirectionDetermined {
            let translation = scrollView.panGestureRecognizer.translationInView(self.view)
            if translation.y > 0 {
                println("UP")
                scrollDirectionDetermined = true
            }
            else if translation.y < 0 {
                println("DOWN")
                scrollDirectionDetermined = true
            }
        }
    }
    
    func scrollViewWillBeginDragging(scrollView: UIScrollView) {
        scrollDirectionDetermined = false
    }
    
    func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
        scrollDirectionDetermined = false
    }
    

提交回复
热议问题