簡體   English   中英

將TapGestureRecognizer添加到除UICollectionView單元格之外的整個視圖

[英]Add a TapGestureRecognizer to whole view except UICollectionView cells

我想添加一個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”功能的正確方法?

實現Gesture Recognizer委托方法

- (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; 
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM