使用autolayout处理iPhone X缺口?

jwa*_*s91 2 ios autolayout swift iphone-x

我有一个imageview,它位于视图顶部的中央.

这在所有设备上看起来都很好,除了iPhone X的缺口裁剪图像.

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

谢谢

Mil*_*sáľ 6

布置时imageView,请使用安全区域指南:

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