Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Implementing Constraints

Jonathan Fernandez
Jonathan Fernandez
4,047 Points

Incorrect Autolayout equation?

At 6:42, the video displays an auto layout equation for the bottom of our view. However, it says: "view.Bottom = (1 * superview.Bottom) + 50.

Shouldn't it be "view.Bottom = (1 * superview.Bottom) - 50." Or even superview.Bottom = (1 * view.Bottom) + 50."

Again, I am not sure if this is right, I recently just read the linked Apple resources.

3 Answers

Yeah, thanks for the clarification man! Yeah, I tried both of your examples on Xcode and I found out that what you just said was true. Can I have that link to Apple?

Jonathan Fernandez
Jonathan Fernandez
4,047 Points

Yeah, of course! https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html#//apple_ref/doc/uid/TP40010853-CH9-SW1

The part that will help you understand our question is when Apple shows an example with a blue and red view. Below that it shows examples of autolayout equations.

This link should also be provided below the respective video by Treehouse.

Jonathan Fernandez
Jonathan Fernandez
4,047 Points

Also, check out the section of "Equality, Not Assignment". Best of luck!

I watched that video too and when I typed

view.Bottom = (1 * superview.Bottom) + 50

it didn't work. I don't know which one of your options might be right, so if you find out can you tell me? I have a feeling that

superview.Bottom = (1 * view.Bottom) + 50

might work.

Jonathan Fernandez
Jonathan Fernandez
4,047 Points

Both are the same actually (just found out today through the Apple documentation). Intuitively, I would choose the first one I mentioned "view.Bottom = (1 * superview.Bottom) - 50." but Apple "recommends" that our constant be positive. So what we can do is "superview.Bottom = (1 * view.Bottom) + 50." The reason being is the = sign is an equality relationship, not an "Assignment operator" as we are use to in swift. Hoped that made sense!

Thanks!