导航栏大标题 - 动画问题

Ale*_*kis 6 html xcode uinavigationbar ios swift

我在导航栏上使用大标题,当我点击一个单元格进入下一个控制器时,大标题有一个奇怪的动画(如下面的 gif 所示)。它不会立即消失。

我尝试了以下解决方案,但没有(https://www.morningswiftui.com/blog/fix-large-title-animation-on-ios13

在此处输入图片说明

我的代码:

在第一个视图控制器上:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        navigationItem.title = "New Order"
        navigationController?.navigationBar.prefersLargeTitles = true
}
Run Code Online (Sandbox Code Playgroud)

在第二个视图控制器上(带有大标题):

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        navigationItem.title = "Menu"
        self.navigationController?.navigationBar.prefersLargeTitles = false
}
Run Code Online (Sandbox Code Playgroud)

编辑:

法比奥的答案是解决方案,但现在我有另一个问题:

当我点击一个单元格时,导航栏的一部分是黑色的(如下所示)

在此处输入图片说明

小智 6

尝试在第一个视图控制器上插入:

 override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    navigationItem.title = "New Order"
    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.largeTitleDisplayMode =  .always
 }
Run Code Online (Sandbox Code Playgroud)

在第二个视图控制器上:

 override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    navigationItem.title = "Menu"
    navigationItem.largeTitleDisplayMode = .never
}
Run Code Online (Sandbox Code Playgroud)


Fab*_*bio 5

对于第二个问题:在 SceneDelegate 中:var window: UIWindow? 在函数场景中放置此行:

window?.backgroundColor = .yourColor
Run Code Online (Sandbox Code Playgroud)

像这样:

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 }
    window?.backgroundColor = .white
}
Run Code Online (Sandbox Code Playgroud)

设置你想要的颜色,就是这样:)