我有FirstViewController
和SecondViewController
。他们有UINavigationBar
不同的颜色。当我显示SecondViewController
时,颜色淡化。我用模拟器和慢动画录制了动画。UINavigationBar奇怪的颜色更改动画时解雇UIViewController
然而,当我去从SecondViewController
回到FirstViewController
,颜色不动画,一切都只是一次改变。
这是我设置为UINavigationBar
的代码SecondViewController
。
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
}
}
我也试图改变UINavigationBar的信息SecondViewController
viewWillDisappear
但它有同样的效果。
我也尝试设置一个backgroundColor
但它并没有改变任何东西。
如何让第二个动画像第一个动画一样工作?
更新
的原因请看SecondViewController
是实物展示。
我只是把它与self.performSegue(withIdentifier: "SecondViewControllerSegue", sender: nil)
我没有任何自定义代码添加到后退按钮,它是默认UINavigationController
实现。
对不起,我误解了你的问题,我删除了答案。您是否尝试过只是手动设置值,而不是仅仅在您的FirstViewController的viewWillAppear方法中从navBarSettings中设置值? – 2017-02-16 10:43:13
是的,我做了,但没有区别 – Yannick
你可以用代码来更新你的问题,你如何推送SecondViewController以及如何弹出它? – 2017-02-16 10:52:56