选择不工作 Collection 容器视图中嵌入的视图

Selection not working Collection view embedded in container view

我在屏幕底部有一个容器视图,它覆盖在主视图之上。 Collection 视图嵌入在容器中,该容器在视图首次加载时隐藏。在主视图控制器上,我有一个点击手势 IBaction,当点击主视图时,unhide/hide 容器视图。

我在 collection 视图的 imageView 上有另一个点击手势 IBaction。我想在点击 collection 视图单元格(图像)时在主视图中加载新内容。

我的问题是当我点击 collection 视图图像时 collectionview(container) 再次被隐藏。在我看来,主视图上的点击手势优先于 collection 视图上的点击手势。我也尝试过在 collection 视图控制器上使用 didselecteditematindexpath 而不是点击手势,但它也不起作用。如果我点击主视图上的任何地方而不是 container/collection 视图,我只希望隐藏容器。我迷路了,请帮忙

我想提一下,无需额外编码,滑动 collection 视图即可正常工作。

检查 Imageview 的 属性 userInteractionEnabled

 containerView.tag = 1234;
 -(IBAction)handleTap:(UITapGestureRecognizer*)recognizer
 {
      if(recognizer.view.tag != 1234)
      {
           //hide container view
      }
 }
give tag to the imageView like 1001

and in handleTap you can check like

if(sender.tag==1001){
NSLog(@"Image Tapped");
}
else{
NSLog(@"Other area of view tapped");
}

不要依赖点击手势来获取集合视图,而是使用委托方法 didSelectItem