Ios 如何在没有情节提要的情况下更改视图控制器

Ios 如何在没有情节提要的情况下更改视图控制器,ios,swift4,Ios,Swift4,我使用以下过程更改视图控制器: let home = MainController.init(nibName: nil, bundle: nil) self.present(home, animated: true, completion: nil) 但在最近的iOS更新之后,我得到了如下信息: 我试过其他方法,但不起作用。如何更改根视图控制器以使其不可见。任何想法或代码片段都会大有裨益!提前感谢您需要启用视图控制器的isModalInPresentation属性 //it will pre

我使用以下过程更改视图控制器:

let home = MainController.init(nibName: nil, bundle: nil)
self.present(home, animated: true, completion: nil)
但在最近的iOS更新之后,我得到了如下信息:


我试过其他方法,但不起作用。如何更改根视图控制器以使其不可见。任何想法或代码片段都会大有裨益!提前感谢

您需要启用视图控制器的
isModalInPresentation
属性

//it will prevent the interactive dismissal of the presented view controller on iOS 13 and later
home.isModalInPresentation = true 
home.modalPresentationStyle = .fullScreen. //use .overFullScreen for transparency
从苹果文档:

当您希望强制承载视图控制器的演示文稿进入模态行为时,会在视图控制器上设置modalInPresentation。当此选项处于活动状态时,演示文稿将阻止交互解除并忽略超出所显示视图控制器边界的事件,直到将其设置为“否”

也可以设置视图控制器的此属性

//it will prevent the interactive dismissal of the presented view controller on iOS 13 and later
home.isModalInPresentation = true 
home.modalPresentationStyle = .fullScreen. //use .overFullScreen for transparency
可能重复的