【发布时间】:2018-06-26 21:18:57
【问题描述】:
在我的应用程序中,我有一个 UINavigationController,我从中推送和弹出 ViewControllers。在某些时候,我想以模态方式显示一个 VC(显示前面的控制器“下方”)。我可以通过在情节提要中设置一个 segue 来让它工作,但是我需要以编程方式完成它,而且我似乎找不到正确的魔法咒语来让它工作。
我看到了几个类似的问题,但他们似乎以模态方式显示 UINavigationController,而不是以模态方式显示 UINavigationController 堆栈上的 VC 之一。
(我在这里放了一个测试应用程序:https://github.com/SuperTango/ModalNavController,这就是这些代码和图像的来源)
“手动”代码可以:
@IBAction func goToVC2Tapped(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destinationViewController = storyboard.instantiateViewController(withIdentifier: "VC2ViewController") as! VC2ViewController
destinationViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.navigationController?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.navigationController?.pushViewController(destinationViewController, animated: true)
}
但它不起作用(请参阅下面 gif 中的第二个转换)。
有效的转场设置如下:
这个 gif 来自测试应用,展示了它如何与 segue 一起工作,但不是手动的。
有什么想法吗?谢谢!
【问题讨论】:
标签: swift uinavigationcontroller