升级到Xcode 8后,tabBar和导航栏变暗了

5
在将我的Xcode更新到Xcode 8之后,我遇到了这个奇怪的问题。我有一个选项卡栏和3个选项卡,当选择选项卡1时,选项卡栏和导航看起来像这样:
选项卡栏的背景颜色是白色,但它显示的是一种深色。

enter image description here

当我选择其他标签时,问题得到解决。
在下面的图片中,我已经选择了tab2。

enter image description here

我不知道为什么会发生这种情况,但在tab1的ViewController中有一个tableView,在tab2中有一个ViewController。

有人知道这是为什么吗?

调试层次结构:

当选择TAB1时 enter image description here


当选择其他选项卡时 在此输入图像描述 我不知道为什么,但是TabBar的UIVisualEffectBackdropView在选项卡1上的背景颜色是黑色,在其他选项卡上是透明的。

这看起来像是你在其上另有一个视图或遮罩。不仅背景不同,选项卡图像的颜色似乎也不同。或者检查一些 alpha 值。如果设置了某些 alpha 值,则之前的 iOS SDK 可能无法理解它。 - pedrouan
请参阅下面的答案。希望这个问题已经解决了。 - John Doe
5个回答

14

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

当我在我的UIViewController的loadView()方法中加入了edgesForExtendedLayout = []这行代码,以停止我的视图进入导航栏下方时,我也遇到了这个精确的问题。因此,删除那行代码,并使用navigationController?.navigationBar.isTranslucent = false来实现相同的目的,则解决了我的问题(虽然John Doe的解决方案可能也是可行的)。我猜当您的工具栏下没有视图时,UIVisualEffectBackdropView会变得不透明,而它正好是黑色的。如果您的工具栏是透明的,看起来就会产生一个黑暗的工具栏。


1
这是有史以来最好的答案!谢谢。 - Sipho Koza

4
您可以在本地解决此问题(例如,如果您有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}

}

我建议您使用全局方法。加入这一行,然后瞧!您将会在此下方匆忙地编写个人感谢消息!


2

结果发现在我的工具栏上添加阴影引起了问题:

以下代码在Xcode7(Swift 2)中为我提供了适当的阴影,但在更新到Xcode8(Swift 3)后,它改变了我的其他栏(选项卡栏+导航栏)的颜色:

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

0

我刚刚将视图控制器的背景颜色属性从.default更改为.systemBackgroundColor


0

在执行segue时,这对我很有帮助:

移除hidesBottomBarWhenPushed或禁用它。

destination.hidesBottomBarWhenPushed = false

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接