Is there any way to know which collection view cell is at a specific point?

cgpoint, ios, objective-c, uicollectionview, uicollectionviewcell

Solution

I haven't used `UICollectionView`s much, but there's a method that seems perfect:

- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point;

The point you pass to the method has to be within the coordinate system of the collection view. You can do:

CGPoint convertedPoint = [collectionView convertPoint:point fromView:viewThatYouGotThePointFrom];

to get the correct point, if the point you got isn't from the collection view originally.

Problem

I have a CGPoint and I would like to know which cell from my collection view currently contains that point. Is there any simple way to do this or do I have to write my own method?

Original source