约束在 iPhone X vs 8 上表现异常(Xcode Bug?)

Constraints behave bizarre on iPhone X vs 8 (Xcode Bug?)

我有一个带有自定义单元格的 tableView,看起来确实像卡片。 因此我有一个包含真实单元格内容的普通 UIView。对于卡片边框之间的距离,这个普通的 UIView 在所有方向上都有 8 个边距。

现在,如果我 运行 iPhone XR 上的应用程序(在布局检查器中用作 "view-as",一切正常)。如果我运行它就iPhone8个单元格运行出来就对了。现在,如果我 select iPhone 8 as "view-as" 并将约束(将值设置为 0 然后返回 8)重置为 8,那么 运行 在 iPhone 8 但是当我 运行 它在 iPhone XR 上时它在右边的距离比 8 更远。

这是错误还是 xcode 以某种方式将 "view-as" 保存到布局中?

"view-as" 设置为 iPhone XR

开iPhone XR

上 Iphone 8

故事板: Storyboard

根据我们上面的讨论,请将您的 shadow 代码替换为 Cell class -

中的以下代码片段
  containerView.layer.shadowPath = UIBezierPath(rect: containerView.bounds).cgPath
  containerView.layer.shadowRadius = 5
  containerView.layer.shadowOffset = .zero
  containerView.layer.shadowOpacity = 0.3
  containerView.layer.cornerRadius = 10.0

完整代码:

override func layoutSubviews() {
    super.layoutSubviews()

    DispatchQueue.main.async {
        containerView.layer.shadowPath = UIBezierPath(rect: containerView.bounds).cgPath
        containerView.layer.shadowRadius = 5
        containerView.layer.shadowOffset = .zero
        containerView.layer.shadowOpacity = 0.3
        containerView.layer.cornerRadius = 10.0
    }

}

如果您还有任何问题,请告诉我。