Swift 当前视图显示图层顶部

Swift present view shows layer the top

我有一个导航控制器,它的根视图控制器是一个 logIn 视图控制器,当用户登录时,它调用 present(..) 来显示不同的屏幕,但我在显示器上有一些特别的东西。如图所示,它显示了两个屏幕之间的层。我无法消除这种行为。我的应用没有故事板。

代码:

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
}

稍后当我在 loginVC 调用它时:

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

输出如图: See the top, the green is the loginVC, the white is the nextVC

如何修复它,让下一个VC覆盖LoginVC?

非常感谢任何帮助!

self.present(self.nextVC, animated: false, completion: nil)

之前插入nextVC.modalPresentationStyle = .fullScreen

结果:

nextVC.modalPresentationStyle = .fullScreen

self.present(self.nextVC, animated: false, completion: nil)

您可以查看文档以获取更多信息 -> 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.


你仍然可以强制执行你想要的 ->

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

奖金

View Controller Presentation Changes in iOS 13