iPhone XR、XS Max上的modalPresentationStyle formSheet问题

6

我正在使用modalPresentationStyle = .formSheet显示模态UIViewController,但在iPhone XR和XS Max上存在一些问题。它被显示在缺口后面。下面的图片从左边是iPhone XR,XS,X。

enter image description here

UIViewController使用自动布局,并以这种方式呈现:

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)

委托:

extension MyController: UIAdaptivePresentationControllerDelegate {

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

使用modalPresentationStyle = .pageSheet时出现了同样的问题。在其他modalPresentationStyles(如全屏)下正常工作。

这是在iOS 12.1,swift 3上的情况。

有什么解决办法吗?谢谢。


我认为你应该向苹果公司报告这个问题。 - Mehul Thakkar
2个回答

1

UIKit不支持该功能。

iPad上唯一的可能性是sheet to full screenpage sheet to form sheet。如文档中所述:

在水平紧凑的环境中,此选项的行为与UIModalPresentationFullScreen相同。

因此,UIKit已经适应了它。

不幸的是,您将不得不实现自己的自定义转换控制器。


UIKit不支持那个是什么意思?我只想解决这个问题,即XR上只有凸起处后面的表格。 - Martin Vandzura
如果我正确理解了您的问题,您正在尝试在紧凑的环境中使用 formSheet。UIKit 不支持它。这在较小的设备上更糟糕。 - GaétanZ

0

正如GaétanZ所说,最好使用另一种模态呈现样式,如overFullScreen用于紧凑的水平尺寸类,而将formSheet留给水平规则的类。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接