1

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 has zPosition -1 and my cells have +1 UIView.isUserInteractionEnabled = true

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

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

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

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

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

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.

Elhoej
  • 741
  • 7
  • 29

2 Answers2

1

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

Use view.addSubview first and then call view.bringSubview(toFront: collectionView!)

Bilal
  • 18,478
  • 8
  • 57
  • 72
0

Why dont you do the selection manually at the moment when the view is tapped:

func selectItem(at: IndexPath?, animated: Bool, scrollPosition: UICollectionViewScrollPosition)

Can you show more in code?

Abadii176
  • 113
  • 7
  • I do, using this to determine which cell is selected: override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { //code here... } – Elhoej Jul 04 '17 at 13:27