iPhone X 上的比例高度问题

Proportional height issues on iPhone X

我很难在 iPhone X 上正确显示 UI,根据屏幕截图,UI 在 iPhone X 上总是比普通 iPhone 更长,是否有关于如何在所有 iPhone 尺寸上正确缩放和显示比例的解决方案?谢谢

使 imageView.widthimageview.height 成正比,而不是 screen height。 我认为在这种情况下,高度与宽度的比例为 4:3 还根据排除安全区域的屏幕高度计算您的图像视图高度。

if #available(iOS 11.0, *) {
    if ((UIApplication.shared.keyWindow?.safeAreaInsets.top)! > CGFloat(0.0)) {
       let safeArealength = UIApplication.shared.keyWindow?.safeAreaInsets.top + UIApplication.shared.keyWindow?.safeAreaInsets.bottom
        height = ratio * (UIScreen.main.bounds.size.height - safeArealength)
        width = 0.75 * height //guess the ratio is 4:3
    }
}

这里的ratioimageview尺寸和screensize的比例。