Last active
June 25, 2019 07:46
-
-
Save anddygon/6e4695ab71e3cbe449880aa8d1a5d2ee to your computer and use it in GitHub Desktop.
ScrollView停止滚动 检测
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //停止滚动检测方式很多 这个方案不管是代码设置的滚动动画 还是 用户触摸事件的停止滚动 都能获取到 效率测试了下还可以 | |
| 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