Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I guess they must refer to the struts and springs model but I can't find any mention of them. When you NSLog constraint they sometimes appear as the description string of the undocumented class NSAutoresizingMaskLayoutConstraint. I have noticed at least 3 different types: h=---, h=--&, h=-&- with horizontal and vertical version.

They turn up a lot when debugging over constrained layouts.

like image 603
Daniel Farrell Avatar asked Jan 12 '13 04:01

Daniel Farrell


People also ask

What is Autoresizing mask?

An integer bit mask that determines how the receiver resizes itself when its superview's bounds change.


2 Answers

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.

like image 145
jrturton Avatar answered Sep 23 '22 20:09

jrturton


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.

like image 23
jmstone617 Avatar answered Sep 25 '22 20:09

jmstone617