Reputation: 859
Is there any easy way of getting Item or index of item when UICollectionView
stops scrolling?
Upvotes: 0
Views: 703
Reputation: 859
This is how I found what item is available on center of the page when UICollectionView Stop Scrolling. Based on this Answer. https://stackoverflow.com/a/24396643/2618600
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"Finished scrolling %@",scrollView);
if ([scrollView isKindOfClass:[UICollectionView class]])
{
UICollectionView *mainCollection = (UICollectionView *) scrollView;
CGRect visibleRect = (CGRect){.origin = mainCollection.contentOffset, .size = mainCollection.bounds.size};
CGPoint visiblePoint = CGPointMake(CGRectGetMidX(visibleRect), CGRectGetMidY(visibleRect));
NSIndexPath *visibleIndexPath = [mainCollection indexPathForItemAtPoint:visiblePoint];
NSLog(@"visibleIndexPath %ld",(long)visibleIndexPath.row);
}
Upvotes: 1
Reputation: 7935
You can use - (NSArray *)indexPathsForVisibleItems
method of UICollectionView
.
Upvotes: 0