如何检测UIScrollView是否空闲超过500毫秒?

时间:2016-02-22 12:47:43

标签: ios objective-c swift timer

我有一个UIScrollView,我打算在委托函数中添加一些代码

func scrollViewDidScroll()

检测滚动视图是否滚动超过500毫秒,但如果滚动视图未滚动,则不会调用该函数。

如何为此案例添加计时器?每当它开始滚动时,计时器就会启动。滚动时,计时器重置。如果500ms没有复位,则定时器触发。

2 个答案:

答案 0 :(得分:1)

有一种方法可以检查值变化UIControlEvents.ValueChanged

将此用于scrollview的属性,例如didScrollToPercentageOffset

(0, 0) means that the scrollView is not scrolled. This is when contentOffset is (0, 0).
(1, 1) means that the scrollView is scrolled to its maximum contentOffset both horizontally and vertically.
(0, 0.5) (for example) means that the scroll view is not scrolled horizontally and is at 50% of it's maximum content offset vertically.

或使用scrollViewDidScroll

的计时器

答案 1 :(得分:0)

  

每当它开始滚动时,计时器就会启动。滚动时,计时器重置。如果500ms没有复位,则定时器触发。

你做到了,你还需要什么?

这是NSTimer类引用:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/