I have a UICollectionView
contained in an UIViewController
that uses a horizontal UICollectionViewFlowLayout
. I'm also using a prototype cell created in my UIStoryboard
. I want to create a custom paging, so I'm using - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
.
The problem is that every time I'm trying to get the indexPath
corresponding to the targetContentOffset (the point in the scroll view where the scroll will stop), the collection view returns nil even though the point is clearly inside the collection view contentSize.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint:(*targetContentOffset)];
// Do something with indexPath
}
What am I doing wrong?