【发布时间】:2020-02-12 00:22:18
【问题描述】:
我正在为两个 UIViewController 实现 UINavigationBar:假设 ControllerA 和 ControllerB。
ControllerA 具有带 backgroundColor = .clear 属性的半透明 UINavigationBar。
ControllerB 具有启用 prefersLargeTitles 的属性和白色背景。
我应该从 ControllerA -> ControllerB 推送和弹出。这是我在 controllerA 生命周期方法中实现的代码:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 11.0, *) {
navigationItem.largeTitleDisplayMode = .never
}
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.backgroundColor = UIColor.clear
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.barTintColor = .clear
navigationController?.navigationBar.titleTextAttributes = [
.font: FontFamily.SFProRounded.bold.font(size: 18),
.foregroundColor: UIColor.white
]
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always
navigationController?.navigationBar.largeTitleTextAttributes = [
.font: FontFamily.SFProRounded.bold.font(size: 22),
.foregroundColor: UIColor.black
]
}
navigationController?.navigationBar.titleTextAttributes = [
.font: FontFamily.SFProRounded.bold.font(size: 18),
.foregroundColor: UIColor.black
]
navigationController?.navigationBar.tintColor = .black
navigationController?.navigationBar.backgroundColor = UIColor.white
navigationController?.view.backgroundColor = UIColor.white
navigationController?.navigationBar.barTintColor = .white
}
下面我在不同 iOS 版本上遇到的问题:
- 版本
点击返回按钮以关闭控制器时动画和标题颜色不正确。视频在这里:https://youtu.be/1g9esUgYDK8
- 版本 == iOS 13
在弹出动画期间,大标题不会随着被解散的控制器移动。视频在这里:https://youtu.be/25k3oz2_wcE
如何解决?提前谢谢你
【问题讨论】:
-
覆盖 B 类中的 viewWillDisapper() 并再次在那里设置普通导航栏。它有助于解决不正确的动画。
-
它不能解决问题
-
我之前也遇到过同样的问题,但我已经完成了上述更改并解决了。
-
我试过了,但不幸的是它没有帮助..看起来我在两个 UINavigationBar 状态之间进行转换完全错误
-
您可以尝试在
ControllerB中覆盖viewWillDisappear并为ControllerA设置导航更改。从viewWillAppear中删除导航设置并将其设置为viewDidLoad。
标签: ios swift uinavigationcontroller uinavigationbar ios-animations