4

我想添加一个 TapGestureRecognizer 来覆盖 UICollectionViewController 的整个屏幕,但 UICollectionViewCell 单元格除外。

我得到的最接近的是

-(void) viewDidLoad {
...
UITapGestureRecognizer *tapAnywhere = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addBoard:)];
[self.collectionView addGestureRecognizer:tapAnywhere];
}

问题:当我点击一个单元格时,不会调用 prepareForSegue 方法。UITapGestureRecognizer 似乎覆盖了单元格。

UICollectionViewController 中的哪个视图是正确的附加 GestureRecognizer 以保留其默认单元格“点击以继续”功能的视图?

4

1 回答 1

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; 
    }
}
于 2013-10-12T23:36:27.863 回答