视图控制器 - 全屏显示

5
第二个视图控制器在顶部有这个间隙,几乎像一个可关闭的弹出窗口显示在手机上。如何使其全屏(删除橙色箭头指向的空间)?

enter image description here


这是在模拟器上还是真实设备上发生的? - Shreeram Bhat
同时发生在模拟器和真实设备中。 - Anand Rockzz
与Xcode 11和iOS 13更新有关吗? - Reinier Melian
2个回答

13

这是iOS 13的一个改变。用户将开始期望能够轻松地滑动关闭模态窗口,因此值得考虑支持该功能。

如果您确实想使用旧的呈现样式,可以在呈现之前设置所呈现的视图控制器的modalPresentationStyle属性来实现。

vc.modalPresentationStyle = .fullScreen

或在视图控制器本身中进行覆盖:

override var modalPresentationStyle: UIModalPresentationStyle {
    get { .fullScreen }
    set { assertionFailure("Shouldnt change that ") }
}

或在故事板中设置segue:

storyboard segue example


这很有帮助!我在每个VC的独立init/viewDidLoad函数中设置了.modalPresentationStyle = .fullScreen,但是那样不起作用。有效的方法是在呈现VC实例之前以编程方式设置.modalPresentationStyle - xta

0
遇到了相同的问题。在您的UIViewController实现中重写prepare for segue方法,将navigationController.modalPresentationStyle设置为.fullScreen。
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  // Get the presented navigationController and the view controller it contains
  let navigationController = segue.destination
    navigationController.modalPresentationStyle = .fullScreen
}

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