Modal UIViewController with presentation style formSheet is not displayed correctly on iPhone XS Max and iPhone XR

1.1k Views Asked by At

I have a view controller presented from a segue modally. Its presentation style is set to Form Sheet.

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    return .formSheet
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.presentationController?.delegate = self
}

On iPhone X and iPhone 8 Plus it works as expected, on iPhone Xs Max and Xr the width of the controller is respected, but the height is wieredly stretched. I have no way of confirming if this is simulator bug, iOS bug or expected behaviour as I don't have Xs Max myself. enter image description here

1

There are 1 best solutions below

0
On

Better use the modal presentation style overFullScreen for compact horizontal size clases and leave the formSheet for the horizontally regular ones.

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    if controller.traitCollection.horizontalSizeClass == .regular {
        return .formSheet
    }
    return .overFullScreen
 }