如何检查 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 何时完成滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Resume game cocos2d(恢复游戏 cocos2d)
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)