【问题标题】:Swift present view shows layer the top [duplicate]Swift呈现视图显示顶层[重复]
【发布时间】:2020-07-28 15:47:09
【问题描述】:

我有一个导航控制器,它的根视图控制器是一个 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

如何解决,让 nextVC 覆盖 LoginVC?

非常感谢任何帮助!

【问题讨论】:

    标签: swift xcode uiviewcontroller uinavigationcontroller


    【解决方案1】:

    您可以查看文档以获取更多信息 -> Apple Documentation

    从 iOS 13.0 开始在 iOS 上默认为 UIModalPresentationAutomatic,在早期版本上默认为 UIModalPresentationFullScreen。 默认情况下,UIViewController 将 UIModalPresentationAutomatic 解析为 UIModalPresentationPageSheet,但其他系统提供的视图控制器可能会将 UIModalPresentationAutomatic 解析为其他具体的呈现样式。


    你仍然可以强行做你想做的事->

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

    奖金

    View Controller Presentation Changes in iOS 13

    【讨论】:

      【解决方案2】:

      self.present(self.nextVC, animated: false, completion: nil)之前插入nextVC.modalPresentationStyle = .fullScreen

      结果:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-18
        • 1970-01-01
        相关资源
        最近更新 更多