那么,在代码中我添加了4个约束。但是当我在UI调试器中运行应用程序时,它显示了额外的6个约束?应该清楚这些4我补充说,我不知道我做错了什么?XCode添加重复约束?
let leftConstr = NSLayoutConstraint(item: image, attribute: .leading, relatedBy: .equal, toItem: cell.contentView, attribute: .leading, multiplier: 1.0, constant: 0.0)
let bottomConstr = NSLayoutConstraint(item: image, attribute: .bottom, relatedBy: .equal, toItem: cell.contentView , attribute: .bottom, multiplier: 1.0, constant: 0.0)
let highthConstr = NSLayoutConstraint(item: image, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 15)
let widthConstr = NSLayoutConstraint(item: image, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 50)
cell.contentView.addConstraints([highthConstr, widthConstr, bottomConstr, leftConstr])
这里是我的UI调试器
https://i.stack.imgur.com/3fzc2.png
我也看到过这种情况。如果我尝试以编程方式制作我的约束,它似乎会自动生成我没有创建的场景以使其工作。也许'翻译自动化大杂烩内容约束'就是这样做的。 – Sethmr