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()
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.
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).
Add that in the controller's field of view this can be fixed:
override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() collectionViewLayout.invalidateLayout() }