Skip to content

Instantly share code, notes, and snippets.

@benvium
Last active September 24, 2015 14:40
Show Gist options
  • Select an option

  • Save benvium/3888e1b21df0cb852c0a to your computer and use it in GitHub Desktop.

Select an option

Save benvium/3888e1b21df0cb852c0a to your computer and use it in GitHub Desktop.
Which UICollectionViewCell will be visible once scrolling finishes? Below assumes a horizontally-oriented UICollectionView.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(CGPoint *)targetContentOffset {
CGPoint point = *targetContentOffset;
// Get point in the Center of the view
CGPoint centerPoint = CGPointMake(point.x + CGRectGetWidth(scrollView.bounds) / 2, point.y);
NSIndexPath *path = [self.collectionView indexPathForItemAtPoint:centerPoint];
if (path) {
NSDate *date = [self indexPathToDate:path]; // My app happens to convert indexPath to date. Yours probably doesn't
DDLogWarn(@"End of scroll is: %@", [self.longDateFormatter stringFromDate:date]); // temp
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment