gpt4 book ai didi

ios - 在 iOS 13 中推送 UIViewController 会导致其与状态栏重叠

转载 作者:行者123 更新时间:2023-12-03 19:48:46 25 4
gpt4 key购买 nike

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

我有一个 UINavigationController 来推送 View Controller 。初始 View Controller 看起来不错。但是当我通过插入另一个 View Controller 来连接它时,第二个 View Controller 与状态栏重叠。这只发生在 iOS 13 中。我在模拟器上测试过。使用 Xcode 11。

导航栏的可见性已隐藏。

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

我使用以下方法进行转换:

self.navigationController?.performSegue(withIdentifier: "myAlertsSegue", sender: self)

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

以下是一些屏幕截图:

初始 View Controller :

Initial View Controller

View Controller 2:

View Controller 2

Storyboard设置:

Xcode 11 storyboard

Segue 属性检查器:

Segue Attributes Inspector

View Controller 2 属性检查器

View Controller 2 Attributes Inspector

更新我所做的解决方法是将每个 View Controller 嵌入到导航 Controller 中。它解决了问题,但过渡并不顺利,因为我无法插入导航 Controller 。我必须介绍它们。我不知道为什么在 iOS 13 上会发生这种情况。

更新我自己找到了答案。请参阅下文是否对您有帮助。

最佳答案

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

差异如下:

  • AppDelegate.swift 中的 UISceneSession 生命周期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.
}
  • 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.
}


}
  • 最后,将其添加到 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>

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

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

关于ios - 在 iOS 13 中推送 UIViewController 会导致其与状态栏重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58129610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com