Detect if UIScrollView is scrolling

前端 未结 4 758
面向向阳花
面向向阳花 2021-02-01 07:21

I\'m looking to detect if (not when) a UIScrollView is scrolling.

i.e.

BOOL isScrolling = myscrollview.scrolling;

How woul

4条回答
  •  悲哀的现实
    2021-02-01 07:40

    Not a very clean solution .. but should be the most reliable:

    var isScrolling = false
    
    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        isScrolling = true
    }
    
    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        if !decelerate { scrollViewDidEndScrolling(scrollView) }
    }
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        scrollViewDidEndScrolling(scrollView)
    }
    
    func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
        scrollViewDidEndScrolling(scrollView)
    }
    
    func scrollViewDidEndScrolling(_ scrollView: UIScrollView) {
        isScrolling = false
    }
    

提交回复
热议问题