Skip to content

Instantly share code, notes, and snippets.

@anddygon
Last active June 25, 2019 07:46
Show Gist options
  • Select an option

  • Save anddygon/6e4695ab71e3cbe449880aa8d1a5d2ee to your computer and use it in GitHub Desktop.

Select an option

Save anddygon/6e4695ab71e3cbe449880aa8d1a5d2ee to your computer and use it in GitHub Desktop.
ScrollView停止滚动 检测
//停止滚动检测方式很多 这个方案不管是代码设置的滚动动画 还是 用户触摸事件的停止滚动 都能获取到 效率测试了下还可以
func scrollViewDidScroll(_ scrollView: UIScrollView) {
isScrolling = true
NSObject.cancelPreviousPerformRequests(withTarget: self)
self.perform(#selector(scrollViewDidEndScrollingAnimation(_:)), with: scrollView, afterDelay: 0.3)
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
NSObject.cancelPreviousPerformRequests(withTarget: self)
//滑动停止
isScrolling = false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment