如何在没有故事板的情况下更改视图控制器
How to change the view controller without storyboard
我曾经使用以下过程更改视图控制器:
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
来自 Apple 文档:
modalInPresentation is set on the view controller when you wish to force the presentation hosting the view controller into modal behavior. When this is active, the presentation will prevent interactive dismiss and ignore events outside of the presented view controller's bounds until this is set to NO.
或者你可以设置视图控制器的属性。
home.modalPresentationStyle = .fullScreen. //use .overFullScreen for transparency
我曾经使用以下过程更改视图控制器:
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
来自 Apple 文档:
modalInPresentation is set on the view controller when you wish to force the presentation hosting the view controller into modal behavior. When this is active, the presentation will prevent interactive dismiss and ignore events outside of the presented view controller's bounds until this is set to NO.
或者你可以设置视图控制器的属性。
home.modalPresentationStyle = .fullScreen. //use .overFullScreen for transparency