1

I have a navigation controller, where its root view controller is a logIn View controller, when the user login, it calls present(..) to display a different screen, but I have something special on the display. As the picture shows, it shows the layers between two screens. I am not able to remove such behavior. My app is without storyboard.

code:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    naviVC = UINavigationController()
    naviVC?.viewControllers = [loginVc!]
    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(frame: UIScreen.main.bounds)

    window?.rootViewController = naviVC
    window?.makeKeyAndVisible()
    window?.windowScene = windowScene
}

Later when I calls this at loginVC:

//nextVC is the next viewController here.
self.present(self.nextVC, animated: false, completion: nil)

Output as the picture shows: See the top, the green is the loginVC, the white is the nextVC

How can I fix it, so the nextVC will cover the LoginVC?

Any help is greatly appreciated!

lom0216
  • 15
  • 3

2 Answers2

0

Insert it nextVC.modalPresentationStyle = .fullScreen before self.present(self.nextVC, animated: false, completion: nil)

result:

nextVC.modalPresentationStyle = .fullScreen

self.present(self.nextVC, animated: false, completion: nil)
Eduard Kanevsky
  • 140
  • 2
  • 6
0

You can check the documentation for more information -> Apple Documentation

Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but other system-provided view controllers may resolve UIModalPresentationAutomatic to other concrete presentation styles.


You can still force to do what you want ->

let controller = UIViewController()
controller.modalPresentationStyle = .fullScreen // or you can use `.overFullScreen` for transparency
present(controller, animated: true)

BONUS

View Controller Presentation Changes in iOS 13

emrcftci
  • 3,355
  • 3
  • 21
  • 35