From 4c95c4bb3bab054439593ad2b84d4726e91aaf95 Mon Sep 17 00:00:00 2001 From: Philippe Bernery Date: Sun, 14 Jun 2015 16:58:15 +0200 Subject: [PATCH] Use `indexPathForItemAtPoint:` for long press. `handleLongPressGesture:` was using `indexPathForItemClosestToPoint:` method to retrieve the index path of the pressed cell. This works well on layouts that fill the entire collection view space but not on other layouts: in the latter case, the closest cell will be selected whereas this is the one under the finger we want to be selected. It now uses `indexPathForItemAtPoint:` instead of `indexPathForItemClosestToPoint:` to get the touched cell. --- DraggableCollectionView/Helpers/LSCollectionViewHelper.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DraggableCollectionView/Helpers/LSCollectionViewHelper.m b/DraggableCollectionView/Helpers/LSCollectionViewHelper.m index 77929f6..855aefd 100644 --- a/DraggableCollectionView/Helpers/LSCollectionViewHelper.m +++ b/DraggableCollectionView/Helpers/LSCollectionViewHelper.m @@ -218,8 +218,8 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)sender return; } - NSIndexPath *indexPath = [self indexPathForItemClosestToPoint:[sender locationInView:self.collectionView]]; - + NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:[sender locationInView:self.collectionView]]; + switch (sender.state) { case UIGestureRecognizerStateBegan: { if (indexPath == nil) {