我有一个具有以下视图架构的应用程序:
UITabBarController > UISplitViewController > UINavigationController > UIViewController
\
> UINavigationController > UIViewController每当我将嵌入在导航控制器中的视图控制器作为详细视图推送时,我都会看到一个奇怪的变色视图出现在主导航栏后面。当我的应用程序同时处于亮模式和暗模式时,就会发生这种情况,如下面的截图所示。
我在一个测试应用程序中重新创建了相同的视图架构,我没有看到变色的视图出现,所以我不确定是什么导致了它。
下面是我用来创建明/暗模式的一些代码:
extension UINavigationBar: RMDThemeable {
func render(for theme: RMDTheme) {
switch theme {
case .light:
barStyle = .default
case .dark:
barStyle = .black
}
}
}
class RMDCollectionViewController: UICollectionViewController {
func render(for theme: RMDTheme) {
switch theme {
case .light:
collectionView?.backgroundColor = UIColor.baseBackgroundLight
case .dark:
collectionView?.backgroundColor = UIColor.baseBackgroundDark
}
}
}这是这个奇怪颜色的截图:



下面是视图调试器:


发布于 2018-06-12 15:30:15
似乎您尚未检查UINavigationController的translucent属性,请将值设置为false或创建具有所需颜色的自定义导航栏。
要设置translucent属性,您可以转到情节提要并选择导航控制器的属性检查器,在顶部将有一个标记为translucent uncheck it的复选框,也可以在如下代码中完成
self.navigationController!.navigationBar.isTranslucent = false获取导航控制器的实例并将其设置为false。
https://stackoverflow.com/questions/50688767
复制相似问题