隐藏和显示状态栏时状态栏闪烁

时间:2018-02-12 08:48:17

标签: ios swift statusbar

在iOS 11中,我遇到状态栏显示/隐藏问题。 但它只是在我改变颜色状态栏时发生

UIApplication.shared.statusBarStyle = .lightContent
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to: #selector(setter: UIView.backgroundColor)) {
    statusBar.backgroundColor = UIColor.black
}

我有两个屏幕。屏幕1显示黑色状态栏,屏幕2显示黑色状态栏。返回屏幕1时,状态栏将闪烁。

我将我的样本上传到Github: https://github.com/phungtai/StatusBar.git

注意:
- 仅限iOS 11.xx.xx
- 更改颜色状态栏时发生,保持默认不会发生。 https://media.giphy.com/media/l3dj1EXWwic3oP6KY/giphy.gif

1 个答案:

答案 0 :(得分:0)

我使用新解决方案更改了状态栏颜色并解决了错误

let statusBar: UIView = UIView()

// In didFinishLaunchingWithOptions AppDelegate

statusBar.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 20)
        statusBarView.backgroundColor = UIColor.black
        UIApplication.shared.statusBarStyle = .lightContent
        let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
        window?.rootViewController?.view.insertSubview(statusBar, aboveSubview: statusBar)