ios 什么是 iPhone X 的“安全区域”(以像素为单位),它会影响顶部缺口和底部栏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46376860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the 'safe region' for iPhone X (in pixels) that factors the top notch and bottom bar?
提问by OnlyCodeMatters
I have read the Human Interface Guidelines for iPhone Xand it doesn't specifically state the 'safe region' (area which caters for both top notch and bottom bar on the iPhone X). I would like to know the pixel dimensions of this region, including the dimensions removed from the top and bottom.
我已经阅读了iPhone X的人机界面指南,它没有具体说明“安全区域”(同时满足 iPhone X 顶部和底部栏的区域)。我想知道这个区域的像素尺寸,包括从顶部和底部移除的尺寸。
回答by MoOx
回答by Tamás Sengel
By printing the safe area insets of the current window with the following code, you can get the point dimensions of the top and bottom safe area.
通过使用以下代码打印当前窗口的安全区域插图,您可以获得顶部和底部安全区域的点尺寸。
if #available(iOS 11.0, *) {
UIApplication.shared.keyWindow?.safeAreaInsets
// ...
}
In portrait, the top area is 44 pointslong and the bottom area is 34 pointsin length.
在纵向中,顶部区域长44 磅,底部区域长34 磅。
Since iPhone X has a @3xresolution, the top area is 132 pixelslong and the bottom area is 102 pixelsin length.
由于 iPhone X 具有@3x分辨率,因此顶部区域长132 像素,底部区域长102 像素。
回答by Adam Haafiz
Xcode 9 introduced safe-area layout guides into the interface builder. You can turn them on by going into your storyboard's file inspector and ticking the checkbox labelled "Use Safe Area Layout Guides"
Xcode 9 在界面构建器中引入了安全区域布局指南。您可以通过进入故事板的文件检查器并勾选标有“使用安全区域布局指南”的复选框来打开它们
From there whenever you add constraints to your root view, you get the option of constraining it to the safe area instead. In this photo, the view in orange is constrained to the edges of the safe area while the view in blue is constrained to the edges of the superview.
每当您向根视图添加约束时,您都可以选择将其约束到安全区域。在这张照片中,橙色的视图被限制在安全区域的边缘,而蓝色的视图被限制在超级视图的边缘。
- Orange view's frame: (0.0, 44.0, 375.0, 734.0)
- Blue view's frame: (0.0, 0.0, 375.0, 812.0)
- 橙色视图的框架:(0.0, 44.0, 375.0, 734.0)
- 蓝色视图的框架:(0.0, 0.0, 375.0, 812.0)
From there we can calculate that 44 points were used for the top safe area while 34 points were used for the bottom area.
从那里我们可以计算出顶部安全区域使用了 44 个点,而底部区域使用了 34 个点。
回答by Enrico Susatyo
You can get it from safeAreaInsets
property of a view in a UIViewController
.
你可以从它safeAreaInsets
在一个视图的属性UIViewController
。