UIScreen.main.bounds 是边到边吗?

Is UIScreen.main.bounds edge to edge?

我有一个相对简单的问题,但我似乎无法在任何地方找到答案。当我使用:

UIScreen.main.bounds.height

这是给我从屏幕底部边缘一直到顶部还是只到安全区域的高度?例如。是直到 iPhone X 的凹口处的高度,还是一直向上超过凹口的高度。

is the height only until the notch for the iPhone X or does it go all that way up past the notch

您可以轻松地自己检查一下。在任何 iOS 项目的某处设置一个断点,并查看当应用程序在您感兴趣的设备上运行时主屏幕由 boundsnativeBounds 返回的矩形,例如iPhone X:

(lldb) po [[UIScreen mainScreen] bounds]
(origin = (x = 0, y = 0), size = (width = 375, height = 812))

(lldb) po [[UIScreen mainScreen] nativeBounds]
(origin = (x = 0, y = 0), size = (width = 1125, height = 2436))

您可以对照 Apple's documentation 中报告的屏幕尺寸进行检查:

我假设 bounds 为主屏幕返回的矩形代表 整个 屏幕,而不仅仅是安全区域。但是如果你仍然不相信,你可以写几行代码来绘制一个具有这些尺寸的矩形,你会看到缺口和角遮挡了矩形的一部分: