Default UICollectionView layout not respecting iPad split screen

Viewed 439

My layout when on split screen is not respecting the width of the split screen.

My custom view is respecting it(the black bar at the top) but anything using autolayout is not respecting the width.

I am handling rotation using

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {

Is there a helper method for handling split view? Do I handle it in layoutSubview? I would have expected the UICollectionView to handle this for us.

In viewWillTransition I use

  guard let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else {
            return
        }

  flowLayout.invalidateLayout()

enter image description here

2 Answers

Yes. That issue still exist in iOS 13 beta 7.

If you implement multiple-window and split two collection view side by side. The only left window will layout correct (rotate several times could see that).

enter image description here

Add that in view controller can fix it:

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()

        collectionViewLayout.invalidateLayout()
    }
Related