54

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.

4
  • Experimenting with this on 10.7.5, I found that NSAMLC seems to not like any attributes but Width and Height. Try to create an NSAMLC for, say, left or bottom, and it'll barf an exception at you. The other things I tried were inequalities, multiplications, and additions, and nothing worked: I couldn't get a single NSAMLC that described itself with an ampersand. So, consider my curiosity piqued. Jan 12, 2013 at 21:28
  • Wow you went quite deep, glad you had fun hacking! I have given up. I thought that knowledge of what these would help my debugging, but actually it doesn't. These errors only turn up when you have an over constrained layout i.e. a superview imposes it's autoresizing mask on your (already) full constrained layout, thereby becoming over constrained. If you see these it normally means you need to set translatesAutoresizingMaskIntoConstraints = NO. Jan 13, 2013 at 3:57
  • What errors? You didn't mention any errors in your question. Jan 13, 2013 at 4:09
  • Excuse my colloquialism; these are not errors (i.e. NSErrors), but I only noticed them when I was debugging autolayout, so I mental associated them with 'errors'. NSAutoresizingMaskLayoutConstraint seems to be an undocumented class. Jan 13, 2013 at 4:24

3 Answers 3

111

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.

2
  • 3
    how about "v=--&"? Would that be fixed top gap, fixed height, flexible bottom gap? Nov 8, 2013 at 12:02
  • Yes, exactly. I didn't bother listing every possible combination :)
    – jrturton
    Nov 8, 2013 at 12:16
3

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.

1
  • don't think the question refers to visual format. It's about interpreting console exceptions Nov 8, 2013 at 11:59
3

Adding to jrturton's answer, the best information I've found to understand the constraint descriptions is the Visual Format Language documentation that you need to create constraints in code. The language is documented as a formal grammar so it may take a minute to absorb it all.

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html#//apple_ref/doc/uid/TP40010853-CH3-SW1

Give you an example:

<NSLayoutConstraint:0x10ada8a70 H:|-(44)-[UIButton:0x10ac5dc30]   (Names: '|':UIView:0x10ac60470)>

This is a Horizontal Orientation constraint (H:) The linkage is 44 pixels from a superview (|) to a UIButton The named superview is a UIView (Names: '|':UIView:) — important to know because you don’t need to be constrained by the immediate superview

The hex values are all valid addresses of your UI elements. When you breakpoint on all exceptions and pause on the constraint conflict, you can use po address to see the object of the constraint. In my case:

(lldb) po 0x10ac5dc30
<UIButton: 0x10ac5dc30; frame = (44 199; 30 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x10ac5ddf0>>

(lldb) po 0x10ac60470
<UIView: 0x10ac60470; frame = (0 64; 320 504); autoresize = RM+BM; animations = { position=<CABasicAnimation: 0x10ac5ec70>; bounds=<CABasicAnimation: 0x10ac62250>; }; layer = <CALayer: 0x10ac60530>>
1
  • 1
    The link is dead :(
    – teradyl
    Jul 10, 2018 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.