首页 文章

当UINavigationController隐藏滚动时,状态栏变为黑色

提问于
浏览
0

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

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
    }

}

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

1 回答

  • 1

    当您有一个 translucent 导航栏时,状态栏会从导航栏中获取其颜色 . 因此,当导航栏滚动时,状态栏将降为默认的黑色 .

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

    你可以在 ViewDidLoad 中添加它

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

    希望这可以帮助

相关问题