I have added a UILongPressGestureRecognizer
to my UICollectionView
that is within a subclass of UIScrollView
. (The UIScrollView
is paged so there are 3 horizontally stacked UIViewController
s).
My code to add the UILongPressGestureRecognizer
:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.delegate = self;
longPress.minimumPressDuration = 0.5;
longPress.delaysTouchesBegan = YES;
[self.collectionView addGestureRecognizer:longPress];
And an NSLog
in my handleLongPress:
method. Currently I hold down on a UICollectionViewCell
, it highlights, but the long press is not activated. I believe my UIScrollView
subclass is consuming the long press and not passing along to the UICollectionView
. When I lift my finger, the didSelectItemAtIndexPath:
method is called.
In my UIScrollView
subclass, the only customization I have is the following:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer {
// This line enables the swipe to delete in the Messaging VC.
return ([otherGestureRecognizer.view.superview isKindOfClass:[UITableView class]]);
}
This was done to enable cell swiping in my UITableView
, which is one of the pages of my UIScrollView
. The swiping works no problem, and I have tried a number of similar checks for UICollectionView
and UICollectionViewCell
here but have not gotten the long press to register yet. Any advice appreciated.
Edit: I have added the long press on another UICollectionView
and it is functional, but the cell never shows highlighted/selected status. I guess that is a clue as to why I can't get this long press gesture to fire.