简体   繁体   English

设置状态栏颜色-延迟?

[英]Set Status bar color - delay?

When ill try to change the text-color of me StatusBar in iOS, there is always a delay for maybe 1-2 seconds. 当尝试在iOS中更改状态栏的文本颜色时,总是会有1-2秒的延迟。 So it starts with black, and after that delay its getting white, as i want to. 因此,它以黑色开始,然后像我想要的那样延迟其变白。

All these changes are in my ViewController, in ViewDidLoad. 所有这些更改都在我的ViewController的ViewDidLoad中。

Ill use a custom view to get an specific color: 不适使用自定义视图来获得特定的颜色:

    let statusBarHeight = CGFloat(20)
    let colorBGView = UIView(frame: CGRectMake(0, -statusBarHeight, self.view.bounds.width, statusBarHeight))
    colorBGView.backgroundColor = UIColor.customDarkerGrey()
    self.navigationController?.navigationBar.addSubview(colorBGView)

And set the barStyle to Black (to get the white color font when using an UINavigationController) 并将barStyle设置为Black(使用UINavigationController时获得白色字体)

    self.navigationController?.navigationBar.barStyle = UIBarStyle.Black

Set the Value for: 设置以下值:

 View controller-based status bar appearance

In the plist.info to "YES" 在plist.info中将其设置为“ YES”

But there is still a "lag" - so everything is white, but it takes up to 2 seconds. 但是仍然存在“滞后”-因此所有内容均为白色,但最多需要2秒。 Any ideas? 有任何想法吗?

Ill found not an answer question, because this is only about coloring, not for the problem with the delay: 病态未找到答案,因为这仅与着色有关,而不是与延迟有关的问题:

preferredStatusBarStyle isn't called 不会调用preferredStatusBarStyle

Edit: 编辑:

Ok, after creating a new Project with 2 ViewControllers and a NavigationController ill found out, that the "Delay" is normal, when you try to change the Color from ViewController to ViewController. 好的,在创建带有2个ViewControllers的新项目并发现NavigationController不适后,当您尝试将Color从ViewController更改为ViewController时,“延迟”是正常的。 It seems, that the function: 看来,该功能:

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
}

Is called with a little delay - and nothing happens when ill add: 稍有延迟就被调用-病态添加时什么也没有发生:

self.setNeedsStatusBarAppearanceUpdate()

So in my case ill changed it globally on the NavigationController, and (because its loaded with my App) you do not recognize the "delay". 因此,就我而言,生病了在NavigationController上进行了全局更改,并且(因为它已随我的应用程序一起加载)您无法识别“延迟”。

Maybe this is helpful for someone else. 也许这对其他人有帮助。

Try to set color for status bar in AppDelegate in method didFinishLaunchinOptions. 尝试使用didFinishLaunchinOptions方法在AppDelegate中为状态栏设置颜色。 As your status bar color is set to other color by default and then you are setting it to new color in your controller, its creating delay. 由于状态栏颜色默认设置为其他颜色,然后在控制器中将其设置为新颜色,因此会延迟创建时间。

And also 并且

Set the Value for: 设置以下值:

View controller-based status bar appearance

In the plist.info to "NO" 在plist.info中将其设为“否”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM