0

OK, a really simple version of this that breaks...

Create a UIView in a nib.

Add an imageView to it. Give the image view a constraint for an Aspect Ratio of 1:1.

Now add constraints from the image view to the edge of the view. (0 size to pin it to the edges).

Now add the view as a UITableView tableHeaderView.

When you run the application on different devices it will break the constraints and remove the aspect ratio constraint. I don't want this, I want it to change the height of the view to be equal to the width.

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:0x7fad01efbbe0 UIImageView:0x7fad047209b0.width == UIImageView:0x7fad047209b0.height>",
    "<NSLayoutConstraint:0x7fad04703630 H:[UIImageView:0x7fad047209b0]-(0)-|   (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
    "<NSLayoutConstraint:0x7fad04703680 V:|-(0)-[UIImageView:0x7fad047209b0]   (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
    "<NSLayoutConstraint:0x7fad04703740 V:[UIImageView:0x7fad047209b0]-(0)-|   (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
    "<NSLayoutConstraint:0x7fad04703790 H:|-(0)-[UIImageView:0x7fad047209b0]   (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
    "<NSLayoutConstraint:0x7fad0429bcf0 'UIView-Encapsulated-Layout-Height' V:[VenueHeaderView:0x7fad047204c0(300)]>",
    "<NSLayoutConstraint:0x7fad0429bca0 'UIView-Encapsulated-Layout-Width' H:[VenueHeaderView:0x7fad047204c0(375)]>" )

Will attempt to recover by breaking constraint  <NSLayoutConstraint:0x7fad01efbbe0 UIImageView:0x7fad047209b0.width == UIImageView:0x7fad047209b0.height>

It seems that there are constraints UIView-Encapsulated-Layout-Height being added to the superview. But these are added with the wrong value. It should recalculate these based on the internal constraints of the header view.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • 1
    Possible duplicate of [Using autolayout in a tableHeaderView](http://stackoverflow.com/questions/28079591/using-autolayout-in-a-tableheaderview) – dev_mush Feb 17 '16 at 12:35
  • 1
    there are many different questions around the topic, if you do a search you'll surely find one that fits your needs. Basically the idea is to compute the height using autolayout and reset your tableview's tableheaderview frame and view. – dev_mush Feb 17 '16 at 12:36
  • Thanks, I had tried searching before and found many of the "solutions" that the linked answer found. I'll take a look at the answer to that one. – Fogmeister Feb 17 '16 at 12:38
  • [self.header setNeedsLayout]; [self.header layoutIfNeeded]; – Kumar Utsav Feb 17 '16 at 14:45
  • @KumarUtsav Hah, nice try. I guess you've tried it and also clicked the link in the comment above? If not, what was the point? – Fogmeister Feb 17 '16 at 14:49
  • I had a similar problem today ended up adding less priority to certain constrains, the warning went away – Jules Feb 19 '16 at 22:56

0 Answers0