So in my tableViewCell I have a imageView which has 0 points constraint to the trailing and leading superview. Top constraints of 8 and Bottom constraint of 30 to the superview. And then I add aspect constraint of the imageView according to the image with this code:
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!)
}
}
}
how is my code breaking any constraints? they have nothing to do with eachother
2017-01-10 21:15:18.502301 Gymkhana[4538:65958] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (
"<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)>" )
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x798fb620
Gymkhana.ThumbnailImageView:0x7869c340.width==Gymkhana.ThumbnailImageView:0x7869c340.height (active)>