在将导航栏设置为透明后,我在恢复 iOS 11 大标题的 bartint 颜色时遇到问题。
复制步骤:
- 将导航栏背景图像和阴影设置为空 UIImage()。
- 导航栏变得透明。
- 将导航栏背景图像和阴影设置为 nil 并设置回栏色调颜色。
- 大标题导航栏变成白色;如果向下滚动(存在旧导航栏),那么您可以看到仅适用于旧式导航栏的条形颜色。
试过:
*将导航背景颜色和状态颜色设置为bar tint color,是的,它改变了,但没有像我们设置bar tint color那样的半透明视觉效果。
有没有人遇到和我一样的问题并且能够用任何解决方案或解决方法来解决它?
原来的
在浏览了一个带有透明导航的页面并返回后
仅供参考,我还应用自定义导航控制器从透明设置回默认颜色,
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
super.pushViewController(viewController, animated: animated)
self.setDefaultNavigationBar()
}
override func popViewController(animated: Bool) -> UIViewController? {
self.setDefaultNavigationBar()
return super.popViewController(animated: animated)
}
override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
self.setDefaultNavigationBar()
return super.popToViewController(viewController, animated: animated)
}
override func popToRootViewController(animated: Bool) -> [UIViewController]? {
self.setDefaultNavigationBar()
return super.popToRootViewController(animated: animated)
}
func setDefaultNavigationBar() {
let navigationBarColor = UIColor(hexString: "#00b5baff")!
self.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationBar.shadowImage = nil
//self.navigationController?.navigationBar.backgroundColor = UIColor.clear
//self.navigationController?.navigationBar.tintColor = UIColor.clear
self.navigationBar.barTintColor = navigationBarColor
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}