On some earlier iOS versions(like iOS 9, 10), scrollViewDidEndDecelerating
won't be triggered if the scrollView is suddenly stopped by touching.
But in the current version (iOS 13), scrollViewDidEndDecelerating
will be triggered for sure (As far as I know).
So, if your App targeted earlier versions as well, you might need a workaround like the one mentioned by Ashley Smart, or you can the following one.
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if !scrollView.isTracking, !scrollView.isDragging, !scrollView.isDecelerating { // 1
scrollViewDidEndScrolling(scrollView)
}
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if !decelerate, scrollView.isTracking, !scrollView.isDragging, !scrollView.isDecelerating { // 2
scrollViewDidEndScrolling(scrollView)
}
}
func scrollViewDidEndScrolling(_ scrollView: UIScrollView) {
// Do something here
}
Explanation
UIScrollView will be stoped in three ways:
- quickly scrolled and stopped by itself
- quickly scrolled and stopped by finger touch (like Emergency brake)
- slowly scrolled and stopped
The first one can be detected by scrollViewDidEndDecelerating
and other similar methods while the other two can't.
Luckily, UIScrollView
has three statuses we can use to identify them, which is used in the two lines commented by "//1" and "//2".
SwiftUI
- See stackoverflow.com/questions/65062590/… – Mofawaw