弹出视图控制器时更改导航栏颜色 [英] Changing navigation bar color while popping view controller
问题描述
我有三个视图控制器.在第一个视图控制器(FirstVC)中,导航栏的栏色调颜色为clearColor,并且栏本身为半透明的.当我单击某些内容时,我将推到SecondVC,在该位置导航栏需要是不透明的.因此,我将barTintColor设置为某个颜色值,并将isTranslucent设置为false.当我从SecondVC推送到ThirdVC时,导航栏再次需要是半透明的.当我弹出ThirdVC并返回SecondVC时,就会出现问题.导航栏显示为一秒钟透明,然后根据需要变为不透明.我无法理解延迟的原因.
I have three view controllers. In the first view controller (FirstVC), the navigation bar's bar tint color is clearColor and the bar itself is translucent. When I click on something, I push to SecondVC where the navigation bar needs to be opaque. So I set the barTintColor to some color value and set isTranslucent to false. When I push to ThirdVC from SecondVC, the navigation bar again needs to be translucent. The issue arises when I pop the ThirdVC and go back to SecondVC. The navigation bar appears as transparent for a second and then becomes opaque as required. I'm unable to understand the reason for the delay.
从SecondVC的viewWillAppear()
中调用以下方法.我曾尝试从ThirdVC的viewWillDisappear()
做同样的事情,但是没有效果.
The following method is called from viewWillAppear()
of SecondVC. I have tried doing the same from the viewWillDisappear()
of ThirdVC, but to no effect.
fileprivate func configureNavigationBar(){
self.navigationController?.navigationBar.setBackgroundImage(nil, for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.barTintColor = Style.Movie.primaryBackgroundColor
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.white]
self.navigationController?.navigationBar.titleTextAttributes = titleDict as? [String:Any]
}
如果我向后滑动而不是点击后退"按钮,效果很好.
It works fine if I swipe back instead of tapping on the back button.
推荐答案
在thiredVC中使用此功能
use this function in thiredVC
override func willMove(toParentViewController parent: UIViewController?) {
self.navigationController?.navigationBar.barTintColor = color use in secondVC
}
这篇关于弹出视图控制器时更改导航栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!