I want to respond to double-taps on cells in a UICollectionView, and have a double-tap action cancel cell selection.
This is what I've tried:
UITapGestureRecognizer *tapRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapRecogniser.numberOfTapsRequired = 2;
for (UITapGestureRecognizer *recogniser in [self.collectionView gestureRecognizers]) {
[recogniser requireGestureRecognizerToFail:tapRecogniser];
}
[self.collectionView addGestureRecognizer:tapRecogniser];
That is, I am trying to get the default gesture recognisers to fail if my double-tap gesture recogniser succeeds.
This doesn't appear to work, as my collection view delegate's collectionView:didSelectItemAtIndexPath:
is still getting called after a double-tap
Note on Apple's UICollectionViewController Docs
Apple's documentation is misleading on this point, claiming that the default gesture recogniser is an instance of a UITapGestureRecognizer subclass, so it can be easily picked out with [recogniser isKindOfClass:[UITapGestureRecognizer class]]
. Unfortunately this is an error.