modalPresentationStyle formSheet issues on iphone XR, XS Max
Asked Answered
T

2

6

I am displaying modal UIViewController with modalPresentationStyle = .formSheet but it has some issues on iphone XR and XS Max. It's displayed behind notch. Image bellow from left side iphone XR, XS, X.

enter image description here

UIViewController use autolayout and is presented like this:

let contentViewController = UINib(nibName: "EditViewController", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! EditViewController

let navController = UINavigationController(rootViewController: contentViewController)

navController.modalPresentationStyle = UIModalPresentationStyle.formSheet
let popover = navController.presentationController!
popover.delegate = self

self.present(navController, animated: true, completion: nil)

delegate:

extension MyController: UIAdaptivePresentationControllerDelegate {

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

There is same issue with modalPresentationStyle = .pageSheet. It works fine with other modalPresentationStyles ie fullscreen

It's on iOS 12.1, swift 3

Any idea how to fix this? Thanks

Tinhorn answered 9/1, 2019 at 9:31 Comment(1)
I think you should report this one to apple.Infiltration
B
1

UIKit does not support that.

The only possibilities are sheet to full screen and page sheet to form sheet on iPad. As specified in the documentation :

In a horizontally compact environment, this option behaves the same as UIModalPresentationFullScreen.

So UIKit already adapts it.

Unfortunately you will have to implement your own custom transition controller.

Belak answered 25/1, 2019 at 17:39 Comment(2)
what do you mean by UIKit does not support that? I just want to fix this issue with sheet behind notch which is only on XRTinhorn
If I understood your problem correctly, you're trying to use formSheet in a compact environment. UIKit does not support it. This is worst on smaller devices.Danyelldanyelle
M
0

As GaétanZ said, better use another modal presentation style like 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
 }
Mathildamathilde answered 13/3, 2019 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.