'Changing UINavigationController Frame in Swift

How can I change the frame of a UINavigationController? I am trying to build a view to verify a users phone number, and want to present it as a pop up view (not full sheet) and also be able to push another view controller on it.

Currently this implementation is presenting as a sheet, not sure why or how to change it so it's only 320x200

func presentPhoneVerify() {
        let vc = VerifyPhoneVC(nibName: "VerifyPhoneView", bundle: nil)
        vc.view.frame = CGRect(x: 100, y: 100, width: 320, height: 200)
        let nav = UINavigationController(rootViewController: vc)
        nav.view.frame = CGRect(x: 100, y: 100, width: 320, height: 200)
        self.present(nav, animated: true, completion: nil)
    }


Solution 1:[1]

Add the UINavigationController as a childViewController. Then set the frame of the UINavigationController. Here is the code.

func presentPhoneVerify() {
    let vc = VerifyPhoneVC(nibName: "VerifyPhoneView", bundle: nil)
    let nav = UINavigationController(rootViewController: vc)
    self.addChild(nav)
    nav.view.frame = CGRect(x: 100, y: 100, width: 320, height: 200)
    self.view.addSubview(nav.view)
    nav.didMove(toParent: self)
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MBT