所以在我的tableViewCell中,我有一個imageView,它對尾隨和領先超視圖有0點約束。頂部約束條件爲8,底部約束條件爲30到超級視角。然後我添加imageView的方面約束根據圖像與此代碼:我的約束破解日誌沒有任何意義,有人可以幫助我理解嗎?
override var image: UIImage? {
didSet {
if let image = image {
let aspect = image.size.width/image.size.height
aspectConstraint = NSLayoutConstraint(item: self,
attribute: NSLayoutAttribute.width,
relatedBy: NSLayoutRelation.equal,
toItem: self,
attribute: NSLayoutAttribute.height,
multiplier: aspect,
constant: 0.0)
}
}
}
internal var aspectConstraint : NSLayoutConstraint? {
didSet {
if oldValue != nil {
self.removeConstraint(oldValue!)
}
if aspectConstraint != nil {
self.addConstraint(aspectConstraint!)
}
}
}
我的代碼是如何打破任何約束?他們無關海誓山盟
2017年1月10日21:15:18.502301金卡納[4538:65958] [LayoutConstraints] 無法同時滿足約束。以下列表中的約束中的至少一個 可能是您不想要的。嘗試 這:(1)看看每個約束,並試圖找出哪些你不期望; (2)找到添加了不需要的約束或約束的代碼並對其進行修復。 (
"<NSLayoutConstraint:0x78698d60 UILabel:0x7869e890'Identical twins play a mi...'.top == UITableViewCellContentView:0x7869e500.topMargin (active)>",
"<NSLayoutConstraint:0x7869c930 V:[UILabel:0x79ba65a0'1h']-(8)-[Gymkhana.ThumbnailImageView:0x7869c340] (active)>",
"<NSLayoutConstraint:0x786a9ef0 H:[Gymkhana.ThumbnailImageView:0x7869c340]-(0)-| (active, names: '|':UITableViewCellContentView:0x7869e500)>",
"<NSLayoutConstraint:0x78689700 H:|-(0)-[Gymkhana.ThumbnailImageView:0x7869c340] (active, names: '|':UITableViewCellContentView:0x7869e500)>",
"<NSLayoutConstraint:0x7869a1b0 V:[Gymkhana.ThumbnailImageView:0x7869c340]-(30)-| (active, names: '|':UITableViewCellContentView:0x7869e500)>",
"<NSLayoutConstraint:0x7869ca10 V:[UILabel:0x7869e890'Identical twins play a mi...']-(8)-[UILabel:0x79ba65a0'1h'] (active)>",
"<NSLayoutConstraint:0x798fb620 Gymkhana.ThumbnailImageView:0x7869c340.width == Gymkhana.ThumbnailImageView:0x7869c340.height (active)>",
"<NSLayoutConstraint:0x79b85b80 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7869e500.height == 329 (active)>",
"<NSLayoutConstraint:0x79b82b80 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x7869e500.width == 320 (active)>")
將嘗試打破約束
<NSLayoutConstraint:0x798fb620
Gymkhana.ThumbnailImageView:0x7869c340.width==Gymkhana.ThumbnailImageView:0x7869c340.height (active)>
恢復
你可以包含約束的字符串和它破壞的約束嗎? –
嘗試刪除底部約束。它仍然給你警告嗎? – Yannick
@yannick刪除底部約束使我的表格視圖單元格縮小,圖像視圖不可查看 – samitarmum