UIScrollViewDelegate has got two delegate methods scrollViewDidScroll:
and scrollViewDidEndScrollingAnimation:
but neither of these tell you when scrolling has completed. scrollViewDidScroll
only notifies you that the scroll view did scroll not that it has finished scrolling.
The other method scrollViewDidEndScrollingAnimation
only seems to fire if you programmatically move the scroll view not if the user scrolls.
Does anyone know of scheme to detect when a scroll view has completed scrolling?
The methods you're looking for are
scrollViewDidEndDragging:willDecelerate:
andscrollViewDidEndDecelerating:
. The first one is always called after the user lifts their finger. If they scrolled fast enough to result in deceleration,willDecelerate
will beYES
and the second method will be called after deceleration completes.(From the UIScrollViewDelegate docs.)
For all scrolls related to dragging interactions, this will be sufficient:
Now, if your scroll is due to a programmatic setContentOffset/scrollRectVisible (with
animated
= YES or you obviously know when scroll is ended):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 usescrollViewDidEndDragging
in this case.An alternative would be to use
scrollViewWillEndDragging:withVelocity:targetContentOffset
which is called whenever the user lifts the finger and contains the target content offset where the scroll will stop. Using this content offset inscrollViewDidScroll:
correctly identifies when the scroll view has stopped scrolling.I've tried Ashley Smart's answer and it worked like a charm. Here's another idea, with using only scrollViewDidScroll
I just had two pages so it worked for me. However, if you have more than one page, it could be problematic (you could check whether the current offset is a multiple of the width but then you wouldn't know if the user stopped at 2nd page or is on his way to 3rd or more)
I only just found this question, which is pretty much the same I asked: How to know exactly when a UIScrollView's scrolling has stopped?
Though didEndDecelerating works when scrolling, panning with stationary release does not register.
I eventually found a solution. didEndDragging has a parameter WillDecelerate, which is false in the stationary release situation.
By checking for !decelerate in DidEndDragging, combined with didEndDecelerating, you get both situations that are the end of scrolling.