When debugging autolayout what is the meaning of the autoresizing mask strings such as h=--& v=-&-?

Solution 1:

If you specify autoresizing masks instead of constraints, or specify no constraints at all, then the view will have NSAutoResizingMaskLayoutConstraint constraints as opposed to NSLayoutConstraints. If you set translatesAutoresizingMaskIntoConstraints to NO, then these constraints do not appear. You can't mix and match on a single view, or you get unsatisfiable constraint errors.

I set up a quick test project with various combinations of autoresizing masks and the logging format is pretty straightforward.

  • h= or v= indicates that we are talking about contraints in the horizontal or vertical direction.
  • - indicates a fixed size
  • & indicates a flexible size
  • The order of symbols represents margin, dimension, margin

Therefore, h=&-& means you have flexible left and right margins and a fixed width, v=-&- means fixed top and bottom margins and flexible height, and so forth.

Solution 2:

If you watch the WWDC 2012 video on Best Practices for Mastering Auto Layout, there is a section in there where the presenter mentions that this is the syntax for views that use Autoresizing Masks and NOT constraints. There's no visual format associated with these like there is for NSLayoutConstraint.