Storyboard 和 AutoLayout:如何设置 UIView 以使用与设备相同的纵横比?

Storyboard and AutoLayout: how to set UIView to use same aspect ratio as device?

在 Storyboard 和 AutoLayout 约束下,有没有办法让 UIView 使用与设备相同的纵横比?

或者是在代码中手动指定的唯一选项?

UIViewController 中的UIView 始终具有相同的比例。 与 UIViewController 无关,您需要确定要关联的屏幕。 (运行时间内可以超过1个)

UIApplication.shared.windows.first?.screen.bounds

会在 运行 时间内为您提供第一个 window 的范围。

本例中的自动版式需要您可以关联的视图。

您的视图和最顶层视图可以有相同的宽度和高度约束。 (监督)