在 iOS 13 中推送 UIViewController 会导致它重叠状态栏

meo*_*w2x 5 iphone xcode ios swift ios13

请注意,这个项目是在 Xcode 10 中创建的。我最近升级到 Xcode 11 并且发生了这种情况。

我有一个推送视图控制器的 UINavigationController。初始视图控制器看起来不错。但是当我通过推动另一个视图控制器转到另一个视图控制器时,第二个视图控制器与状态栏重叠。这仅发生在 iOS 13 中。我在模拟器上进行了测试。使用 Xcode 11。

导航栏的可见性被隐藏。

将演示文稿设置为全屏或当前上下文具有相同的结果。它似乎超出了安全区域,但我将其设置在安全区域下方。

我过渡使用:

self.navigationController?.performSegue(withIdentifier: "myAlertsSegue", sender: self)
Run Code Online (Sandbox Code Playgroud)

这个项目是在Xcode 10中创建的,我更新到Xcode 11后遇到这个问题,如果我在Xcode 11中新建一个项目,好像没有问题。我猜,我有一个迁移问题。

以下是一些截图:

初始视图控制器:

初始视图控制器

视图控制器 2:

视图控制器 2

故事板设置:

Xcode 11 故事板

Segue 属性检查器:

Segue 属性检查器

视图控制器 2 属性检查器

视图控制器 2 属性检查器

更新 我所做的解决方法是将每个视图控制器嵌入到导航控制器中。它解决了问题,但过渡并不顺利,因为我无法推送导航控制器。我不得不展示它们。我不知道为什么在 iOS 13 上会发生这种情况。

更新 我自己找到了答案。看看下面是否对你有帮助。

meo*_*w2x 4

我找到了我自己问题的答案。我尝试在 Xcode 11 中创建一个新项目,以查看与 Xcode 10 中创建的项目相比的差异。这些差异与仅在 iOS 13 中可用的 UISceneSession 有关。我希望这个答案可以帮助所有遇到相同问题的人我愿意。

这里的差异:

  • UISceneSession 的生命周期中AppDelegate.swift 有针对 UISceneSession 的方法。将这些行添加到AppDelegate.swift.
// MARK: UISceneSession Lifecycle

    @available(iOS 13.0, *)
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    @available(iOS 13.0, *)
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
Run Code Online (Sandbox Code Playgroud)
  • SceneDelegate.swift

这是一个要创建的新类。

import UIKit

@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }
    }

    func sceneDidDisconnect(_ scene: UIScene) {
        // Called as the scene is being released by the system.
        // This occurs shortly after the scene enters the background, or when its session is discarded.
        // Release any resources associated with this scene that can be re-created the next time the scene connects.
        // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
    }

    func sceneDidBecomeActive(_ scene: UIScene) {
        // Called when the scene has moved from an inactive state to an active state.
        // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
    }

    func sceneWillResignActive(_ scene: UIScene) {
        // Called when the scene will move from an active state to an inactive state.
        // This may occur due to temporary interruptions (ex. an incoming phone call).
    }

    func sceneWillEnterForeground(_ scene: UIScene) {
        // Called as the scene transitions from the background to the foreground.
        // Use this method to undo the changes made on entering the background.
    }

    func sceneDidEnterBackground(_ scene: UIScene) {
        // Called as the scene transitions from the foreground to the background.
        // Use this method to save data, release shared resources, and store enough scene-specific state information
        // to restore the scene back to its current state.
    }


}
Run Code Online (Sandbox Code Playgroud)
  • 最后,将其添加到 Info.plist
<key>UIApplicationSceneManifest</key>
    <dict>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UISceneClassName</key>
                    <string></string>
                    <key>UISceneDelegateClassName</key>
                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneStoryboardFile</key>
                    <string>Main</string>
                </dict>
            </array>
        </dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <false/>
    </dict>
Run Code Online (Sandbox Code Playgroud)

另外,请注意,当移动到另一个 Storyboard 时,您可能需要设置modalPresentationStyle = .fullScreen.

清理并构建。希望这可以帮助。如果对您有用,请投票。