简体   繁体   English

如何确保 iOS 13 模态视图控制器呈现正确的状态栏颜色?

[英]How can I ensure iOS 13 modal view controllers present the right status bar colour?

With the new iOS 13 view controller changes , view controllers are being presented that don't cover the whole screen.随着新的 iOS 13 视图控制器的变化,视图控制器的呈现不会覆盖整个屏幕。 They instead leave a black space at the top.相反,他们在顶部留下了一个黑色空间。 However, the system status bar is not changing colour automatically.但是,系统状态栏不会自动更改颜色。 When I present a modal view controller, the status bar is staying with now-invisible black text (and a green battery which looks super weird in the middle of nowhere).当我展示一个模态视图控制器时,状态栏保持着现在不可见的黑色文本(和一个绿色的电池,在偏僻的地方看起来非常奇怪)。

How do I make the bar behave in the same way as within Apple's apps, where the bar animates to different colour when a modal popup appears?如何使栏的行为与 Apple 应用程序中的行为相同,当出现模式弹出窗口时,栏会以不同的颜色进行动画处理?

I've tried setting modalPresentationCapturesStatusBarAppearance to true on my modal controllers, to no luck.我已经尝试在我的模态控制器modalPresentationCapturesStatusBarAppearance设置为 true ,但没​​有运气。

The bar in my presenting view controller is a UINavigationBar, and is not part of a navigation controller.我的呈现视图控制器中的栏是 UINavigationBar,而不是导航控制器的一部分。 The presenting VC is its delegate, and I've overridden position(for bar: UIBarPositioning) to return .topAttached.呈现的 VC 是它的委托,我已经覆盖了position(for bar: UIBarPositioning)以返回 .topAttached。

I've tried presenting the modal with .modalPresentationStyle = .formSheet and without setting .modalPresentationStyle at all.我试过用.modalPresentationStyle = .formSheet呈现模态, .modalPresentationStyle = .formSheet没有设置 .modalPresentationStyle 。 Neither worked.都没有工作。

Broken:破碎的:

损坏的视图控制器

The presenting VC:主讲VC:

呈现视图控制器

Expected Behaviour:预期行为:

![预期行为,如日历应用程序中所示

Two things:两件事情:

The modal view controllers need to have VC.modalPresentationCapturesStatusBarAppearance = false .模态视图控制器需要有VC.modalPresentationCapturesStatusBarAppearance = false This is the default but if, like me, you set it to something else, make sure it's false!这是默认设置,但如果像我一样将其设置为其他内容,请确保它为 false!

You need to ensure that View controller-based status bar appearance in your info.plist is set to YES .您需要确保 info.plist 中View controller-based status bar appearance设置为YES I'd messed around with it in an attempt to make my status bar the right colour but having it set to NO was a problem.我弄乱了它,试图使我的状态栏具有正确的颜色,但将其设置为NO是一个问题。

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

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