0

When adding a constraint, how to I tell which side of the view the constraint starts from? (Read below to understand what I mean).

This is driving me crazy. Lets say I have a scroll view which should have a frame of (0, 20, 320, height - 40). So obviously I want to add Vertical space of 20 to Top Layout guide and one of 20 to the bottom layout guide.

But when I control drag from the scroll view, to the Top Layout Guide, it adds a constraint of -528 Vertical Spacing (The bottom of the scroll view is -528 off from the Top Layout Guide). I would like the top of the scroll view to be 20 away from the Top Layout Guide, and the constraint not to refer to the bottom of the scroll view.

1 Answer 1

0

If you nudge the scrollview down so that it isn't lined up to the top of the superview, then when you create constraint between top layout guide and the scrollview, it will make the constraint between layout and the top of the scrollview.

4
  • I might have misunderstood what you mean, but the scroll view has a frame rectangle of (0,20,320,528). So it's not lined up with the superview.
    – Lord Zsolt
    Nov 21, 2013 at 12:55
  • @LordZsolt Hmm. The only way I can get it to replicate what you describe is by adding the scrollview with a frame of 0,0,320,568 and then trying to add the top layout constraint. But if I drag it to 0,20,320,548 and then add the constraint (or choose "reset to suggested constraints"), I get the constraint between the top layout guide and the top of the scrollview.
    – Rob
    Nov 21, 2013 at 13:06
  • 1
    Well this is interesting... I just clicked that red arrow which indicates problem with constraints. Selected Add Missing Constraints and it added like 5 constraints, which fixed the issue o.O
    – Lord Zsolt
    Nov 21, 2013 at 13:36
  • @LordZsolt yeah, ib is a bit of a mystery sometimes when it comes to constraints.
    – Rob
    Nov 21, 2013 at 13:37

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.