Default UICollectionView layout does not fit iPad split screen

My layout when split screen doesn't account for the width of the split screen.

My custom view respects it (black bar at the top), but whatever is used in autodetect is out of width.

I am handling the rotation with

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

      

Is there a helper method for handling split view? Am I processing it in layoutSubview

? I would expect a UICollectionView to handle this for us.

In viewWillTransition I am using

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

  flowLayout.invalidateLayout()

      

enter image description here

+4


source to share


2 answers


I assume you mean by default UICollectionViewFlowLayout

. It looks like the itemSize is wider than the view. Try adding a check collectionView:layout:sizeForItemAtIndexPath:

to make sure the width is less than or equal to the width of the collection.



0


source


Yes. This issue still exists in iOS 13 beta 7.

If you are implementing multiple windows and sharing two collection views side by side. The only left window will be correctly positioned (it could be rotated several times).

enter image description here



Add that in the controller's field of view this can be fixed:

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()

        collectionViewLayout.invalidateLayout()
    }

      

0


source







All Articles