当UICollectionView下方有一个UIView时,如何使单元格可选? [英] How can I make my cells selectable when there is an UIView below the UICollectionView?

查看:87
本文介绍了当UICollectionView下方有一个UIView时,如何使单元格可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集合视图,并在其下方添加了一个UIView.单元格显示在其顶部,但是它们是不可选择的.我该如何再次选择它们?

I have a collection view, and added a UIView below it. The cells shows up on top of it, but they aren't selectable. How can I make them selectable again?

到目前为止我尝试过的事情:

What I have tried so far:

UIView的zPosition -1,我的单元格的+1 UIView.isUserInteractionEnabled = true

UIView has zPosition -1 and my cells have +1 UIView.isUserInteractionEnabled = true

我尝试将UIView都添加为view.addSubview和collectionView?.addSubview

I have tried to add the UIView both as view.addSubview and collectionView?.addSubview

collectionView?.insertSubview(UIView,belowSubview:collectionView!)

collectionView?.insertSubview(UIView, belowSubview: collectionView!)

这个人有同样的问题,没有提供解决方案:插入UICollectionView下面的子视图

This guy has the same problem, with no solution provided: Inserting Subview Below UICollectionView

我正在使用此代码来确定选择了哪些单元格

I'm using this code to determine what cells are selected

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
    //Code here...
}

当下面没有UIView时,这一切都起作用.但是我想为我的collectionview内容插图提供一个可见的容器",所以我创建了一个UIView. 问题是,当使用下面的UIView单击单元格时,上面的代码根本不会被触发.

It all works when there is no UIView below. But I want to have a visible "container" for my collectionview content insets, so I created an UIView. Problem is the above code doesn't get fired at all when clicking on the cells with the UIView below.

推荐答案

之所以会这样,是因为您的其他视图覆盖了集合视图.

It's happening because your other view is covering the collection view.

首先使用view.addSubview,然后调用view.bringSubview(toFront: collectionView!)

这篇关于当UICollectionView下方有一个UIView时,如何使单元格可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆