0

I have code for my collectionView that adjusts the content so that it sits beneath the navigation bar.

        collectionView.contentInsetAdjustmentBehavior = .never
        let tabBarHeight = self.tabBarController?.tabBar.bounds.height
        let navBarHeight = self.navigationController?.navigationBar.bounds.height
        self.edgesForExtendedLayout = UIRectEdge.all
        self.collectionView.contentInset = UIEdgeInsets(top: navBarHeight!, left: 0.0, bottom: tabBarHeight!, right: 0.0)

This works well on every other device on iOS 11 except for iPhone X, on iPhone X, the content sits behind the nav bar and toolbar on app start.

Is there something I am missing for iPhone X specifically?

Thanks

Khoury
  • 411
  • 1
  • 4
  • 21
  • Check your collection view constraints. Maybe it's related to `superview` not to `SafeArea` or `Top Layout guide`. – Chanchal Chauhan Apr 09 '18 at 06:31
  • You're correct, the constraints are related to the superview. I've changed them to the top layout guide, but now when I scroll the collection view, you can't see the cells blur behind the nav bar and toolbar? – Khoury Apr 10 '18 at 10:26

1 Answers1

1

I think you forgot to calculate the height of status bar. Before iPhone X, the height of status bar is 20pt and in iPhoneX it is 44pt. That's the reason you can not see the complete cell.

To do that, add your constraints from superview and write the following code:

    cv.contentInsetAdjustmentBehavior = .never
    let tabBarHeight = self.tabBarController?.tabBar.bounds.height ?? 0
    let statuBarHeight = UIApplication.shared.statusBarFrame.height
    let navBarHeight = self.navigationController?.navigationBar.bounds.height ?? 0
    self.edgesForExtendedLayout = UIRectEdge.all
    cv.contentInset = UIEdgeInsets(top: navBarHeight+statuBarHeight, left: 0.0, bottom: tabBarHeight, right: 0.0)

Hope this helps :)

Chanchal Chauhan
  • 1,530
  • 13
  • 25