gpt4 book ai didi

ios - 将 TapGestureRecognizer 添加到除 UICollectionView 单元格之外的整个 View

转载 作者:可可西里 更新时间:2023-11-01 05:22:02 25 4
gpt4 key购买 nike

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

我得到的最接近的是

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

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

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

最佳答案

实现手势识别器委托(delegate)方法

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

关于ios - 将 TapGestureRecognizer 添加到除 UICollectionView 单元格之外的整个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19340272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com