gpt4 book ai didi

ios - 解除 UIViewController 时 UINavigationBar 奇怪的颜色变化动画

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:01 24 4
gpt4 key购买 nike

我有一个 FirstViewController 和一个 SecondViewController。它们的 UINavigationBar 有不同的颜色。当我显示 SecondViewController 时,颜色逐渐淡化。我用模拟器和慢动画录制了动画。

Animation Show

但是,当我从 SecondViewController 返回到 FirstViewController 时,颜色没有动画,一切都立即改变。

Animation Dismiss

这就是我在 SecondViewController 中为 UINavigationBar 设置代码的方式。

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let navBar = self.navigationController?.navigationBar {

navBar.barStyle = UIBarStyle.black
navBar.barTintColor = NavBarColor.red
navBar.backgroundColor = NavBarColor.red
navBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
navBar.isTranslucent = false
navBar.tintColor = .white
}
}

在我的FirstViewController 类中,我创建了一个结构NavBarSettings 并保存了UINavigationBar 的信息。然后我在 viewWillAppear 中应用它们。

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let navBar = self.navigationController?.navigationBar,
let navBarSettings = self.navBarSettings {

navBar.barStyle = navBarSettings.barStyle
navBar.barTintColor = navBarSettings.barTintColor
navBar.backgroundColor = navBarSettings.backgroundColor
navBar.titleTextAttributes = navBarSettings.titleTextAttributes
navBar.isTranslucent = navBarSettings.isTranslucent
navBar.tintColor = navBarSettings.tintColor

}
}

我也尝试在 SecondViewController viewWillDisappear 中更改 UINavigationBar 信息,但它具有相同的效果。

我也尝试设置一个 backgroundColor 但它也没有改变任何东西。

如何让第二个动画像第一个一样工作?

更新

SecondViewController 的转场很好看。

我只是用 self.performSegue(withIdentifier: "SecondViewControllerSegue", sender: nil)

调用它

我没有向后退按钮添加任何自定义代码,它是默认的 UINavigationController 实现。

最佳答案

尝试用自定义后退按钮替换后退按钮并向其添加操作。

let backButton = UIButton()
backButton.addTarget(self, action: #selector(self.backButtonClicked), for: UIControlEvents.touchUpInside)
navBar.navigationItem.leftBarButtonItem = barButton

func backButtonClicked() {
// try implementing the same thing here but with the self.navigationController?.popViewController(animated: true)
}

关于ios - 解除 UIViewController 时 UINavigationBar 奇怪的颜色变化动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42271324/

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