An example of where you want to do this is when you want to capture a gesture in a UICollectionView, and then do something with a specific element in a UICollectionView that falls under the swipe gesture layout. The code below as a method in your UICollectionViewController will return the correct cell and allow for scrolling in the collection view.
- (UICollectionViewCell *) cellForGesture:(id)sender { UISwipeGestureRecognizer * gesture = sender; CGPoint point = [gesture locationInView:self.view]; NSLog(@"Swipe location: %f, %f", point.x, point.y, nil); CGPoint pointInCollection = CGPointMake(point.x + self.collectionView.contentOffset.x, point.y + self.collectionView.contentOffset.y); NSIndexPath * indexPath = [self.collectionView indexPathForItemAtPoint:pointInCollection]; UICollectionViewCell * cell = [self.collectionView cellForItemAtIndexPath:indexPath]; return cell; }
You can call the above method in this context (where revealSupplementalControls is a custom method in your UICollectionViewCell class):
- (IBAction) swipeLeft:(id)sender { UICollectionViewCell * cell = [self cellForGesture:sender]; [cell revealSupplementalControls]; }
Duncan babbage
source share