如何在模态 swift 4 中呈现 ViewController
Posted
技术标签:
【中文标题】如何在模态 swift 4 中呈现 ViewController【英文标题】:How to present ViewController in modaly swift 4 【发布时间】:2017-12-22 04:59:30 【问题描述】:如何以模态显示 viewController。我是 ios 的新手,正在使用 swift4 我试试这个
let userVC = mainStoryboard.instantiateViewController(withIdentifier:
"menuC") as! MenuController
userVC.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
userVC.navigationController?.modalPresentationStyle =
UIModalPresentationStyle.overCurrentContext
present(userVC, animated: true, completion: nil)
【问题讨论】:
【参考方案1】:这样做
if let presentedViewController = self.storyboard?.instantiateViewController(withIdentifier: "menuC")
presentedViewController.providesPresentationContextTransitionStyle = true
presentedViewController.definesPresentationContext = true
presentedViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext;
presentedViewController.view.backgroundColor = UIColor.init(white: 0.4, alpha: 0.8)
self.present(presentedViewController, animated: true, completion: nil)
【讨论】:
以上是关于如何在模态 swift 4 中呈现 ViewController的主要内容,如果未能解决你的问题,请参考以下文章
UIAlertController 错误当在 swift 中以模态呈现的视图控制器中调用时
从 UINavigationVController 导航以模态方式呈现到根 UINavigationVController - swift