I'd like to add a TapGestureRecognizer to cover the whole screen of a UICollectionViewController except the UICollectionViewCell cells.
The closest I got was
-(void) viewDidLoad {
...
UITapGestureRecognizer *tapAnywhere = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addBoard:)];
[self.collectionView addGestureRecognizer:tapAnywhere];
}
Problem: When I tap a cell the prepareForSegue method is not called. The UITapGestureRecognizer seems to cover the cell.
Which View in a UICollectionViewController is the right one to attach the GestureRecognizer to retain its default cell "tap to segue" functionatlity?
Implement Gesture Recognizer delegate method
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isKindOfClass:[UICollectionViewCell class]]) //It can work for any class you do not want to receive touch
{
return NO;
}
else
{
return YES;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With