我想添加一个TapGestureRecognizer来覆盖除UICollectionViewCell单元格之外的UICollectionViewController的整个屏幕。
我最接近的是
-(void) viewDidLoad {
...
UITapGestureRecognizer *tapAnywhere = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addBoard:)];
[self.collectionView addGestureRecognizer:tapAnywhere];
}
问题:当我点击一个单元格时,不会调用prepareForSegue方法。 UITapGestureRecognizer似乎涵盖了单元格。
UICollectionViewController中哪个View是连接GestureRecognizer以保留其默认单元格“tap to segue”功能的正确方法?
答案 0 :(得分:7)
实施手势识别器委托方法
- (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;
}
}