How to know exactly when a UIScrollView's scrolling has stopped?

后端 未结 6 1036
慢半拍i
慢半拍i 2020-12-04 22:07

In short, I need to know exactly when the scrollview stopped scrolling. By \'stopped scrolling\', I mean the moment at which it is no longer moving and not being touched.

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 22:56

    I found a solution:

    -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
    

    I did not notice that last bit before, willDecelerate. It is false when the scrollView is stationary when ending the touch. Combined with the above-mentioned speed check, I can snap both when it's slow (and not being touched) or when it's stationary.

    For anyone not doing any snapping but needs to know when scrolling stopped, didEndDecelerating will be called at the end of the scroll movement. Combined with a check on willDecelerate in didEndDragging, you'll know when the scrolling has stopped.

提交回复
热议问题