With a similar problem to this question , I am trying to add a double-touch gesture recognizer to an instance of a UICollectionView .
I need the default single click to UICollectionViewDelegate collectionView:didSelectItemAtIndexPath: method.
To do this, I implement the code directly from the Apple Collection View Programming Guide (Listing 4-2) :
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; NSArray* recognizers = [self.collectionView gestureRecognizers];
This code does not work as expected: tapGesture fired by double-clicking, but by default it is not used once, and the delegate method didSelect... is still called.
Passing through the debugger shows that the if condition, [aRecognizer isKindOfClass:[UITapGestureRecognizer class]] , is never evaluated as true, and therefore the failure tapGesture not set on the new tapGesture .
Running this debugger command every time through a for loop:
po (void)NSLog(@"%@",(NSString *)NSStringFromClass([aRecognizer class]))
shows that the default gesture recognizers are (really) not instances of UITapGestureRecognizer .
Instead, they are private classes UIScrollViewDelayedTouchesBeganGestureRecognizer and UIScrollViewPanGestureRecognizer .
Firstly, I cannot use them explicitly without violating the Private API rules. Secondly, joining UIScrollViewDelayedTouchesBeganGestureRecognizer via requireGestureRecognizerToFail: does not seem to give the desired behavior, i.e. The didSelect... delegate didSelect... is still being called.
How can I work with UICollectionView default gesture recognizers to add a double click to a collection view and prevent a single click from turning off the delegate method of collectionView:didSelectItemAtIndexPath: :?
Thanks in advance!