How to handle background tap in UICollectionView
ios, ios7, iphone, objective-c, uicollectionview
Solution
This is how I tried to set gesture recognizer to background view. I managed to get separate events.
self.collectionView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg"]];
self.collectionView.backgroundView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
self.collectionView.backgroundView.gestureRecognizers = @[tapRecognizer];
Problem
I have a `UICollectionView` in my app and I want to handle the background tap of it to do some cool stuff, but I tried several solutions and neither of them was too good. Things I've tried: - Adding a background view behind the `UICollectionViewCells` and handling the tap on that - Adding a `UITapGestureRecognizer` to the `UICollectionView`'s view (which is the same as it's `collectionView` property) The problem in both cases is that while it handles the tap of the background perfectly, it also handles the tap when it's on a `UICollectionViewCell`, so when the user selects an item, but in that case it shouldn't because these 2 things have different actions in my app.