简体   繁体   English

iOS状态栏背景与UIAlertController重叠

[英]iOS status bar background overlaps UIAlertController

The main view of my app is a scrollable UICollectionView embedded in a UITabBarController . 我的应用程序的主视图是嵌入在UITabBarController的可滚动UICollectionView I'm not using a navigation bar and when the user scrolls he sees the cells behind the status bar, because the status bar has no background. 我没有使用导航栏,当用户滚动时,他看到了状态栏后面的单元格,因为状态栏没有背景。

状态栏后面的单元格

I've used UIApplication.shared.statusBarView?.backgroundColor = .white in my AppDelegate to apply a background and to make the status bar look like desired. 我在AppDelegate中使用了UIApplication.shared.statusBarView?.backgroundColor = .white来应用背景并使状态栏看起来像期望的那样。

This works fine, but doesn't look nice when you're presenting a UIAlertController . 这可以正常工作,但在呈现UIAlertController时看起来并不好。

UIAlertController和状态栏背景

The white status bar stays above the dimmed background. 白色状态栏保持在背景变暗的上方。

Is there a better way to apply a background to the status bar or a way to keep it behind the UIAlertController background? 是否有更好的方法将背景应用于状态栏或将其保留在UIAlertController背景后面?

You can try to use a UIView with a background color at the top of your presenting UIView . 你可以尝试使用UIView与您呈现顶部的背景颜色UIView

Height of status bar can come from UIApplication.shared.statusBarFrame . 状态栏的高度可以来自UIApplication.shared.statusBarFrame And update your view size when receiving UIApplication.didChangeStatusBarFrameNotification . 并在收到UIApplication.didChangeStatusBarFrameNotification时更新视图大小。

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

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