Problems with Contraints for the UITextField

It took me about 10 tries to get this right. If you are having problems, note that in the previous chapter we were told to do:

Align: Horizontal Centers Update Frames => Items of New Constraints

But in this chapter, we are told to do:

Align: Horizontal Centers Update Frames => All Frames in Container

I’m not sure how you are supposed to know which one to do.

You only want to “Update Frames” for a view when it has all of the constraints it needs. For example, if you have a view and it has a top, bottom, leading, and trailing constraint, then it almost certainly has enough information to determine the frame, so “Updating Frames” will make sure that the view is not misplaced. On the other hand, if you have a view and just add a top constraint, the view doesn’t have enough information to determine its frame, so “Updating Frames” will not work (it doesn’t know where the view should go).

In general, “Update Frames” when a view is misplaced (you’ll get a warning in Interface Builder if a view is misplaced). Knowing when you can use “Update Frames for Items of New Constraints / All Frames in Container,” just like with all of Auto Layout, just takes practice and experience.