[英]How to Push ViewController in new window
我需要通过代码在新窗口中推送viewController
。 我正在做下面的代码,但它不起作用。
let win = UIWindow(frame: UIScreen.main.bounds)
let nc = UINavigationController(rootViewController: self)
nc.view.backgroundColor = .clear
win.rootViewController = nc
win.windowLevel = UIWindow.Level.alert + 1
win.makeKeyAndVisible()
有谁知道,如何在新窗口中推送一个 viewController?
下面的代码有效
采用全局变量:
var window2 : UIWindow?
修改后的代码如下
let win = UIWindow(frame: UIScreen.main.bounds)
let nc = UINavigationController()
nc.pushViewController(self, animated: true)
nc.navigationBar.isHidden = true
nc.view.backgroundColor = .clear
win.rootViewController = nc
window2 = win
win.windowLevel = UIWindow.Level.alert + 1
win.makeKeyAndVisible()
并关闭我在下面所做的新窗口
if let nc = window2?.rootViewController as? UINavigationController {
nc.popViewController(animated: true)
}
window2?.resignKey()
window2 = nil
注意:它没有显示推送和弹出默认动画,而是当前它没有任何类型的动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.