【发布时间】:2017-02-16 10:32:16
【问题描述】:
我有一个FirstViewController 和一个SecondViewController。他们的UINavigationBar 有不同的颜色。当我显示SecondViewController 时,颜色会逐渐消失。我用模拟器录制动画和慢动画。
但是,当我从 SecondViewController 回到 FirstViewController 时,颜色没有动画,一切都立即改变。
这就是我在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类中,我创建了一个structNavBarSettings,并保存了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
}
}
我也试过更改SecondViewControllerviewWillDisappear中的UINavigationBar信息,但效果一样。
我也尝试设置backgroundColor,但它也没有改变任何东西。
如何让第二个动画像第一个一样工作?
更新
转至SecondViewController 是一种善意的表现。
我只是用self.performSegue(withIdentifier: "SecondViewControllerSegue", sender: nil)调用它
我没有在后退按钮上添加任何自定义代码,它是默认的UINavigationController 实现。
【问题讨论】:
-
对不起,我误解了你的问题,我已经删除了答案。您是否尝试过手动设置值,而不是简单地在 FirstViewController 的 viewWillAppear 方法中从 navBarSettings 设置?
-
是的,但没有区别
-
您能否用代码更新您的问题,说明您如何推送 SecondViewController 以及如何弹出它?
-
@Sneak 我更新了问题。对你有帮助吗?
-
是的,我以前试过。 Clinton 找到了解决方案,感谢您的帮助 Sneak :)
标签: ios swift uinavigationbar