如何检测 iOS 中的圆角屏幕角

How to detect rounded screen corners in iOS

在 (https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x) Apple 告诉我们 "A full-width button appearing at the bottom of the screen looks best when it has rounded corners and is aligned with the bottom of the safe area..."

所以如果屏幕的角是圆的,我想把我的按钮的角变圆,但是当屏幕的角很尖时,我想把按钮的角变圆。

我只是想看看应用程序是 运行 在 iPhone X 上,但我希望未来的设备也有圆角,我不想再访问了每次有新设备出来都会有这个代码。

我已经在我的应用委托中检查了 window.layer.cornerRaidus...

考虑到我们必须如何检查我们是否在 iphone-x(例如,请参阅 ),我认为没有而且很快就会有一种干净的方法来找出这一点。

此外,在我看来,安全区的存在表明不希望检测到这一点。安全区域是一个你可以在里面画的矩形,你不应该在它外面画,或者我什至会说你甚至不应该关心那里有什么(或没有什么)。

摘自Positioning Content Relative to the Safe Area

Safe areas help you place your views within the visible portion of the overall interface.

这就是保证可用于您的布局的内容,您不应该真正关心它的外部。

关于 the guidelines 你引用了:

Inset full-width buttons.

A button that extends to the edges of the screen might not look like a button. Respect the standard UIKit margins on the sides of full-width buttons. A full-width button appearing at the bottom of the screen looks best when it has rounded corners and is aligned with the bottom of the safe area—which also ensures that it doesn't conflict with the Home indicator.

请注意,这里没有提到屏幕的圆角。因此,尽管可以合理地假设这是他们推荐这种布局的原因,但我不会过早地尝试概括它。

不检测圆角,而是检测底部安全区域下方的 non-zero 区域。如果该区域足够大,则与其对齐(但显然不在其中),并可能围绕按钮角作为您对未来的随机赌注。如果不是,请在按钮下方保留标准 auto-layout 底部边距并使用标准按钮 UI。

无论您做什么,请注意 Apple 可能或将会更改其 UI 指南和 UI API 和外观,因此不要计划您的 future-proof 设计 future-proof.