且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查 UITableView 何时完成滚动

更新时间:2023-02-05 23:03:04

你将实现 UIScrollViewDelegate 协议方法如下:

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
}

斯威夫特版本

public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    if decelerate {
        scrollingFinished()
    }
}

public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    scrollingFinished()
}

func scrollingFinished() {
    print("scrolling finished...")
}

对于上述委托方法当用户的手指在拖动内容后触摸起来时,滚动视图会发送此消息.UIScrollView 的 decelerating 属性控制减速. 当视图减速停止时,参数decelerate将为NO.

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.

第二个用于缓慢滚动,甚至当你的手指触摸时滚动停止,正如 Apple Documents 所说,当滚动运动停止时.

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.