更新到 Xcode 8 后 tabBar 和导航栏变暗了

tabBar & navigation bar became dark after updating to Xcode 8

将我的 Xcode 更新为 Xcode 8 后,我遇到了这个奇怪的问题。当 tab1 是 selected 标签栏并且导航看起来像这样时,我有一个标签栏和 3 个标签:

标签栏的背景颜色为白色,但显示为深色

当我 select 任何其他选项卡时,问题得到解决

在下图中,我 select编辑了 tab2

我不知道为什么会这样,但在 tab1 的 ViewController 中我有一个 tableView,在 tab2 中我有一个 ViewController

有人知道为什么会这样吗??

调试层次结构:

当 TAB1 被 select编辑时


当 selected 任何其他选项卡时

我不知道为什么,但是 tabbar 的 UIVisualEffectBackdropView 的背景颜色在 tab1 上是黑色的,而在 tab1 上是透明的 其他标签

原来在我的工具栏上添加阴影导致了问题:

下面的代码在 Xcode7 (swift 2) 中给了我适当的阴影,但在更新到 Xcode 8 (swift 3) 后,它改变了颜色我的其他栏(标签栏+导航栏):

toolbar.layer.masksToBounds = false
toolbar.layer.shadowOffset = CGSize(width: -1, height: 1)
toolbar.layer.shadowRadius = 1
toolbar.layer.shadowOpacity = 0.5

您可以在本地(例如,如果您有 CustomTabBarController)和全局解决此问题。我在这里为您提供两种解决方案:

1.本地:

    class YourCustomTabBarVC: UITabBarController {

    //MARK:- Initializers
    required init?(coder aDecoder:NSCoder) {
        super.init(coder: aDecoder)
        __customInit()
    }  

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        __customInit()
    }

    fileprivate func __customInit() {
        addObservers()

       //Customize TabBar appearance:
        tabBar.backgroundColor = UIColor.white
    }
    }

2。全局:在您的 AppDelegate.swift:

 func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions
    launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
   /* Your other code*/   
   UITabBar.appearance().backgroundColor = UIColor.white // {UR_DESIRED_COLOR}

}

我建议你使用全局方法。添加那一行,瞧!你会争先恐后地在这里写一封个人感谢信!

对于因与 OP 不同的原因而遇到此问题的其他人:

当我将行 edgesForExtendedLayout = [] 添加到我的 UIViewController 的 loadView() 方法到 stop my view going under the navigation bar 时,我遇到了这个确切的问题。因此,删除该行并使用 navigationController?.navigationBar.isTranslucent = false 为我修复了相同的目标(尽管 John Doe 的解决方案也可能是可行的)。我想当你的工具栏下没有视图时,UIVisualEffectBackdropView 变得不透明,它恰好是黑色的。如果您的工具栏是透明的,这似乎会产生一个黑色的工具栏。

这在执行 segue 时帮助了我:

删除 hidesBottomBarWhenPushed 或禁用它。

destination.hidesBottomBarWhenPushed = false

我刚刚将视图控制器的 background color 属性 从 .default 更改为 .systemBackgroundColor