Search code examples
swiftuicollectionviewiphone-x

UICollection view section gaps with added subview on iphoneX


I have I think an iphoneX specific problem. There's a collection view with 2 sections and I'm adding subview, which should only appear when you drag the last section down.

But on iPhoneX it's visible all the time, which not that I want. How do I fix that?

iphoneX enter image description here

That's what it should be like (other displays)

enter image description here

My code for subview:

func setupGenres() {

    genreView.frame.size = CGSize(width: view.frame.size.width, height: view.frame.width / 7)
    genreView.frame.origin.x = -2 // = 0
    genreView.frame.origin.y = collectionView.frame.size.height / 3 - genreView.frame.size.height
    genreView.backgroundColor = UIColor.clear
    genreView.alpha = 1
    collectionView.addSubview(genreView)

    featuredGenre.frame.size = CGSize(width: view.frame.size.width / 5.75, height: view.frame.size.width / 15)
    featuredGenre.frame.origin.x = view.frame.size.width / 29.57

    pickView.frame.size = CGSize(width: featuredGenre.frame.size.width * 1.25, height: featuredGenre.frame.size.height * 1.2)
    pickView.center.x = featuredGenre.center.x
    pickView.frame.origin.y = genreView.frame.size.height / 2 - pickView.frame.size.height / 2
    pickView.backgroundColor = UIColor.white
    pickView.layer.cornerRadius = pickView.frame.size.height / 2
    genreView.addSubview(pickView)

    ... and so on with other subviews
}

What might be the problem?


Solution

  • It took me a week to find that magic checkbox. enter image description here