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 Build a Playlist Browser with Swift Building the Music Library and Playlist Models Using UIImageView

dexter foo
dexter foo
8,233 Points

Why don't we need to update frames when we add the alignment, width and height constraints?

Sorry i may have missed something when learning constraints, but why is it that we don't have to update frames when we add the constraints, horizontal center in container and vertical center in container and when we add the width and height constraints for the UIImageView?

1 Answer

When you are working in Xcode interface builder and you add constraints, sometimes the changes do not take effect right away. When you update the frame it changes the view to display as it will with the new constraints applied.

In Xcode you will see a red box with dashes, this is where the view will be drawn when you app runs. This may be different then what is currently being displayed in interface builder.

Example

If you were to update the frame for this view it would move it to where the red box is. In some cases this is what we want, in other cases we want to make sure our view is displayed in the spot where we have it in interface builder. We can change the constraints to make sure that the view is placed in the exact area we want it to in interface builder which is represented by the blue markers you see.