使用自动布局处理 iPhone X 缺口?

Handling iPhone X notch with autolayout?

我有一个图像视图,它位于视图顶部的中央。

这在所有设备上看起来都不错,除了 iPhone X 缺口会裁剪图像。

有没有一种方法可以从屏幕的凹口而不是顶部角定位视图?因为它导致我的布局一致性问题

谢谢

布局 imageView 时,使用 safe area guides:

NSLayoutConstraint.activate([
    imageView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
    // rest of the constraints
])