Ios UINavigationBar在禁用UIViewController时奇怪的颜色更改动画
我有一个Ios UINavigationBar在禁用UIViewController时奇怪的颜色更改动画,ios,swift,uinavigationbar,Ios,Swift,Uinavigationbar,我有一个FirstViewController和一个SecondViewController。它们的UINavigationBar有不同的颜色。当我显示SecondViewController时,颜色会很好地淡出。我用模拟器和慢速动画录制了动画 但是,当我从SecondViewController返回到FirstViewController时,颜色不会设置动画,所有内容都会立即更改 这是我在SecondViewController中为UINavigationBar设置代码的方式 overri
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
类中,我创建了一个结构NavBarSettings
,并保存UINavigationBar的信息。然后,我会在视图中应用它们
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
viewwilldiscover
中的UINavigationBar信息,但效果相同
我还尝试设置背景色
,但也没有改变任何东西
如何让第二个动画像第一个一样工作
更新
到SecondViewController
的顺序是一种表演
我只是用self.performsgue(标识符:“SecondViewControllerSegue”,发送者: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)
}
对不起,我误解了你的问题,我已经删除了答案。您是否尝试过手动设置值,而不是仅在第一个ViewController中的ViewWillExample方法中通过navBarSettings设置值?是的,我尝试过,但没有区别。您可以用代码更新问题,说明如何推送第二个ViewController以及如何弹出它?@Sleek我更新了问题。它对你有帮助吗?是的,我以前试过。克林顿找到了解决办法,谢谢你的帮助(偷偷摸摸:)谢谢!:)
self.navigationController?.popViewController(动画:true)
部分实现了这个技巧