3

I'm working in a UICollectionViewand I'm using the "Setion Header" option, everything is working fine except that in landscape mode the iPhone X does not fill completely.

I tried to find a solution for example with this but it does not work for me:

    if #available(iOS 11.0, *) {
        myCollection?.contentInsetAdjustmentBehavior = .always
    }

Any suggestions on this?

In portraid it looks good:

my collection app

PORTRAID

Order of my views:

views

AlbertB
  • 637
  • 6
  • 16

2 Answers2

2

You can use size classes for it.

In Storyboard click on view as at the bottom :

enter image description here

and change the orientation to landscape.

Select the trailing constraint of collectionView :

enter image description here enter image description here

introduce the variation for the constraint for compact-compact as -44.

enter image description here

The final UI will be :

enter image description here

Repeat the same process for leading constraint. Hope it helps what you want to achieve here. Happy coding

Edit

Googled and got the same question in SO:

May be this helps what you want to achieve.

Amit
  • 4,837
  • 5
  • 31
  • 46
  • Thanks for the suggestions, I'm trying but the order of my views: https://i.stack.imgur.com/PPjuX.jpg Trailing space: superview no safeArea. My view is inside `collection reusable view` – AlbertB Aug 08 '18 at 05:27
  • Sorry I forgot to mention that Leading and trailing constraints of `collectionView` – Amit Aug 08 '18 at 05:33
  • A query, I just see that the content of the UICollection also moved under the notch? – AlbertB Aug 08 '18 at 06:35
  • With its suggestion and adding this code works perfectly (the content of the UICOLLECTION no longer moves, only the header section) `if let flowLayout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout { if #available(iOS 11.0, *) { flowLayout.sectionInsetReference = .fromSafeArea } }` – AlbertB Aug 08 '18 at 14:45
1

Remove Leading trailing constraints and add Leading and trailing constraints 0 from view not from safe area for your collection view.

enter image description here

Chanchal Chauhan
  • 1,530
  • 13
  • 25