how to check when UITableView is done scrolling

后端 未结 4 1803
天涯浪人
天涯浪人 2020-12-17 09:37

Is there a way to check if my tableview just finished scrolling? table.isDragging and table.isDecelerating are the only two methods that I can find

4条回答
  •  轮回少年
    2020-12-17 10:18

    You would implement UIScrollViewDelegate protocol method as follows:

    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
        if (!decelerate) {
            [self scrollingFinish];
        }
    }
    
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
        [self scrollingFinish];
    }
    
    - (void)scrollingFinish {
        //enter code here
    }
    

    Swift version

    public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        if decelerate {
            scrollingFinished()
        }
    }
    
    public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        scrollingFinished()
    }
    
    func scrollingFinished() {
        print("scrolling finished...")
    }
    

    For the above delegate method The scroll view sends this message when the user’s finger touches up after dragging content. The decelerating property of UIScrollView controls deceleration. When the view decelerated to stop, the parameter decelerate will be NO.

    Second one used for scrolling slowly, even scrolling stop when your finger touch up, as Apple Documents said, when the scrolling movement comes to a halt.

提交回复
热议问题