0

I need to push viewController in the new window by code. I am doing below code but its not working.

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()

Does anyone have idea, how to push a viewController in new window?

Vipul Kumar
  • 893
  • 9
  • 19
dahiya_boy
  • 9,298
  • 1
  • 30
  • 51

1 Answers1

0

Swift 5.x

Below code works

took global variable:

var window2 : UIWindow?

Modified code with below

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()

And dismiss new window I did below

if let nc = window2?.rootViewController as? UINavigationController {
    nc.popViewController(animated: true)
}

window2?.resignKey()
window2 = nil

Note: It is not showing push and pop default animation, rather currently it is working w/o any kind of animation.

Ref : To create a new UIWindow over the main window

dahiya_boy
  • 9,298
  • 1
  • 30
  • 51