How to detect when a UIScrollView has finished scrolling
The 320 implementations are so much better - here is a patch to get consistent start/ends of the scroll.
-(void)scrollViewDidScroll:(UIScrollView *)sender { [NSObject cancelPreviousPerformRequestsWithTarget:self]; //ensure that the end of scroll is fired. [self performSelector:@selector(scrollViewDidEndScrollingAnimation:) withObject:sender afterDelay:0.3]; ...}-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ [NSObject cancelPreviousPerformRequestsWithTarget:self];...}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { [self stoppedScrolling];}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { if (!decelerate) { [self stoppedScrolling]; }}- (void)stoppedScrolling { // ...}
For all scrolls related to dragging interactions, this will be sufficient:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { _isScrolling = NO;}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { if (!decelerate) { _isScrolling = NO; }}
Now, if your scroll is due to a programmatic setContentOffset/scrollRectVisible (with animated
= YES or you obviously know when scroll is ended):
- (void)scrollViewDidEndScrollingAnimation { _isScrolling = NO;}
If your scroll is due to something else (like keyboard opening or keyboard closing), it seems like you'll have to detect the event with a hack because scrollViewDidEndScrollingAnimation
is not useful either.
The case of a PAGINATED scroll view:
Because, I guess, Apple apply an acceleration curve, scrollViewDidEndDecelerating
get called for every drag so there's no need to use scrollViewDidEndDragging
in this case.