botbot
botbot

Reputation: 7359

Why are some constraints nested and others not in XCode 6?

If I tap on a label and add constraints they will appear as nested in the left menu. But when I do the same thing to the button, the constraints are not nested in the button's view tree. Am I doing something wrong?enter image description here

Upvotes: 0

Views: 136

Answers (1)

Matt Gibson
Matt Gibson

Reputation: 38238

"The view that holds the constraint must be an ancestor of the views the constraint involves, and should usually be the closest common ancestor. (This is in the existing NSView API sense of the word ancestor, where a view is an ancestor of itself.)"

So, to take a few of your examples:

  1. The constraints on the Hello label are height and width constraints, and involve only the label itself. Therefore the closest ancestor is the label itself, so that's where the constraints are.

  2. The first Vertical Space constraint is between the Button and its containing View, so the closest ancestor of them both is the containing View.

  3. The last Vertical Space constraint is between the Bottom Layout Guide and the Button. Their closest common ancestor is the containing View, so that's where the constraint lives.

Upvotes: 2

Related Questions