iOS 状态栏背景与 UIAlertController 重叠 [英] iOS status bar background overlaps UIAlertController
问题描述
我的应用程序的主视图是一个嵌入在 UITabBarController
中的可滚动的 UICollectionView
.我没有使用导航栏,当用户滚动时,他会看到状态栏后面的单元格,因为状态栏没有背景.
The main view of my app is a scrollable UICollectionView
embedded in a UITabBarController
. 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.
我在 AppDelegate 中使用了 UIApplication.shared.statusBarView?.backgroundColor = .white
来应用背景并使状态栏看起来像所需的一样.
I've used UIApplication.shared.statusBarView?.backgroundColor = .white
in my AppDelegate to apply a background and to make the status bar look like desired.
这很好用,但是当您呈现 UIAlertController
时看起来不太好.
This works fine, but doesn't look nice when you're presenting a UIAlertController
.
白色状态栏保持在变暗的背景之上.
The white status bar stays above the dimmed background.
是否有更好的方法将背景应用到状态栏或将其保持在 UIAlertController
背景后面?
Is there a better way to apply a background to the status bar or a way to keep it behind the UIAlertController
background?
推荐答案
您可以尝试在呈现的 UIView
顶部使用带有背景颜色的 UIView
.
You can try to use a UIView
with a background color at the top of your presenting UIView
.
状态栏的高度可以来自UIApplication.shared.statusBarFrame
.并在收到 UIApplication.didChangeStatusBarFrameNotification
时更新您的视图大小.
Height of status bar can come from UIApplication.shared.statusBarFrame
. And update your view size when receiving UIApplication.didChangeStatusBarFrameNotification
.
这篇关于iOS 状态栏背景与 UIAlertController 重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!