I'm using a UICollectionView
to scroll through a set of thumbnails quickly. Once scrolling ends, I'd like to display a larger hi-res version of the current thumbnail.
How can I detect when the user has completed scrolling? I do implement didEndDisplayingCell
, but that only tells me when a particular cell has scrolled off; it doesn't tell me when the scroll motion actually completes.
Swift 3 version of Abey M and D6mi 's answers:
When scroll is caused by user action
When scroll is caused by code action (programmatically): (like "scrollRectToVisible" or "scrollToItemAtIndexPath")
Notes:
.
and somewhere in your viewWillAppear make the class its own delegate
Just to cover your bases you should implement both these UIScrollViewDelegate methods. In some cases there may not be a deceleration (and
scrollViewDidEndDecelerating
would not be called), for e.g., the page is fully scrolled in place. In those case do your update right there inscrollViewDidEndDragging
.An important fact to note here :
This method gets called on User initiated scrolls (i.e a Pan gesture)
On the other hand, this one gets called on all manually (programatically) initiated scrolls (like
scrollRectToVisible
orscrollToItemAtIndexPath
)if you want to use the visible indexpath:
UICollectionView
is a subclass ofUIScrollView
. So if you have set the delegate and implementedUIScrollViewDelegate
, you should be able to detect this the same way asUIScrollView
.For eg:-
As per documentation, the above method should tell when the scroll view has ended decelerating the scrolling movement.
Swift 3 version: