我以编程方式添加了所有视图以及它们的自动布局约束。 在我的一个视图中,我使用以下方法禁用了状态栏:
override var prefersStatusBarHidden: Bool { return true }显然,这会导致safeAreaLayoutGuide在任何不是iPhone X的东西上移动20px。在我的情况下,这导致iPhone 6/7/8 / SE等顶部没有足够的填充。
解决这个问题的最简洁方法是什么? 如何在iPhone 8视图中添加填充而不将其添加到iPhone X?
I am adding all of my views programmatically as well as their auto layout constraints. In one of my views I have disabled the status bar using this:
override var prefersStatusBarHidden: Bool { return true }Apparently this causes the safeAreaLayoutGuide to be moved by 20px on anything that isn't the iPhone X. And in my case this results in not having enough padding at top for the iPhone 6/7/8/SE etc.
What's the cleanest way to work around this? How would you add padding e.g. on the iPhone 8 views without adding it to the iPhone X?
最满意答案
您可以使状态栏透明以保留空间,而不是使用prefersStatusBarHidden 。 在间距方面,这对iPhone X没有影响。
let statusBarWindow = application.value(forKey: "statusBarWindow") as? UIWindow statusBarWindow.alpha = 0.0"statusBarWindow"实际上是私有API,因此最好像"status" + "BarWindow"类的那样将它拉开。
You could make the status bar transparent to keep the space instead of using prefersStatusBarHidden. In terms of spacing this will have no effect on iPhone X.
let statusBarWindow = application.value(forKey: "statusBarWindow") as? UIWindow statusBarWindow.alpha = 0.0"statusBarWindow" is actually private API, so better pull it apart like "status" + "BarWindow" or something like that.
更多推荐
发布评论