如何检查 UITableView 何时完成滚动

how to check when UITableView is done scrolling(如何检查 UITableView 何时完成滚动)
本文介绍了如何检查 UITableView 何时完成滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

有没有办法检查我的 tableview 是否刚刚完成滚动?table.isDraggingtable.isDecelerating 是我能找到的仅有的两种方法.我不确定当 tableview 完成滚动时如何预测或收到通知.

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. I am not sure how I can either anticipate or get notified when the tableview finishes scrolling.

我可以以某种方式使用计时器来检查 tableView 是否正在滚动吗?

Can I somehow use timers to check every second if the tableView is scrolling or not?

推荐答案

你将实现 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.

这篇关于如何检查 UITableView 何时完成滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定义、交互式)视图控制器呈现和解除处理滚动视图)