【问题标题】:Status bar turn to black when UINavigationController hides on scroll当 UINavigationController 在滚动时隐藏时,状态栏变为黑色
【发布时间】:2018-05-07 10:04:34
【问题描述】:

我在我的应用程序中使用 collectionView 并将状态栏样式设置为亮起并将 navigationControllerhidesBarsOnSwipe 设置为 true。但是当我向上滚动单元格时,navigationController 被隐藏,但状态栏变为黑色。并在将 collectionView 向下滚动时返回白色。这是我的导航控制器代码:

extension UINavigationController {

    override open var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }

    func transparentNavigation() {

        guard let pacificoFont = UIFont(name: "Pacifico", size: 20) else {return}

        navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.foregroundColor, NSAttributedStringKey.font: pacificoFont]

        navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        navigationBar.shadowImage = UIImage()
        navigationBar.isTranslucent = true
        view.backgroundColor = .clear
        hidesBarsOnSwipe = true
    }

}

有没有办法修复这个“功能”?

【问题讨论】:

标签: ios swift uinavigationcontroller xcode9


【解决方案1】:

当您有一个translucent 导航栏时,状态栏的颜色来自导航栏。结果导航栏滚动时,状态栏会变成默认的黑色。

如果您希望translucent 导航栏和状态栏具有特定颜色(如白色),您可以使用

您可以添加到ViewDidLoad

    let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
    statusBar.backgroundColor = UIColor.white

希望对你有帮助

【讨论】:

  • 不,没用。因为我需要透明背景的状态栏。此解决方案添加白色背景。
  • @jack-daniel : 在statusBar.backgroundColor = 指定你需要的颜色,伙计
  • 我将颜色更改为 UIColor.clear,但没有。它从白色变为透明背景,但问题保持不变。
猜你喜欢
  • 1970-01-01
  • 2014-11-29
  • 1970-01-01
  • 2014-02-07
  • 1970-01-01
  • 2016-03-17
  • 2017-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多