When clicking the gray background and selecting the Resolve Auto Layout Issues menu, the choice for Update Frames is grayed out. Any ideas?
Anything you can select in a storyboard has a name. How about being a little more specific about what you clicked on? Look in the storyboard’s table of contents.
Update frames means: Move the elements you specified into the positions dictated by the constraints you added. If the elements you specified are already in the positions dictated by the constraints, then you can’t update them. If any of the constraints for an item are orange, that means the position of the item needs to be updated. If the constraints are blue, then the item is in the same position as the position dictated by the constraints.
The exact text I am having issues with is:
‘Since the text field’s font changed, the views on the canvas now are misplaced. Select the gray background view, open the Resolve Auto Layout Issues menu, and select Update Frames from the All Views in View Controller section. The text field and labels will be repositioned to match their constraints (Figure 4.6).’
The Update Frames selection is grayed out.
I am not an expert at all, that is why I am taking my time through this book, and so far, it has been awesome.
Did you do this:
If you did, then read #1 again and post the information. If you didn’t understand #1, here it is in some other words: When you select anything in a storyboard, Xcode will tell you what is selected. Often times you can’t know what is selected by looking at the storyboard itself, because views are stacked on top of each other–but the storyboard has a table of contents, which lists every item in the storyboard, and the selected item will be highlighted. The table of contents may not be visible, and if that’s the case you will have to learn how to make it visible (there’s a picture on p. 13). After doing that, post the name of the item that the storyboard’s table of contents says is selected.
I did select the gray background view, and the item that is selected is ‘View’, which has ‘degrees Fahrenheit’, ‘is really’, ‘degrees Celsius’, ‘value’, ‘100’, and ‘Constraints’ under it.
Are there any constraints listed under View? If not, there are no constraints to update.
If you want to see how things are supposed to work, then create a new project and add 5 labels randomly spaced vertically:
The labels do need to be lined up underneath each other, i.e. not to the left or right horizontally.
Then go back to the top of p. 63 and follow the instructions up to p. 67. They do work. It’s good practice anyway. However, I suggest that you never follow the book’s instructions to Update Frames in the same menu where you add constraints. Just follow the instructions to add constraints, and when the books says to Update Frames, ignore it; then click the button to add the constraints. Subsequently, click on the Resolve Auto Layout Issues icon (to the right of the Pin icon), then choose Update Frames. Adding constraints and updating frames are two separate steps and they are much easier to understand if you do them separately.
Once you get that to work, delete all the constraints (use the table of contents), then go back to p. 63 and use the same steps to set the distance between the labels to 30; then after you add the TextField, pin the TextField 100 from the top and 30 from the label underneath it. Before you click on Update Frames each time, try to figure out what is going to happen, then observe what actually happens.
Thanks for the advice. Starting to make some sense!
I too had issues with this. The book method just flat out doesn’t work, maybe something changed in Xcode. I take a longer way to do auto-constraints but it works each time, consistently.
Here’s how I fixed it:
-First, clear all constraints.
-Second, select all subviews and go to AlignMenu -> Horiztonally In Container (make this zero), make sure Update Frames is set to “None” and Click “Add 5 Constraints”.
-Third, select all subviews and open the Pin menu and change the top strut to 8 and click “Add 5 constraints”.
-Fourth, you will likely get an error so simply click the view, go to the “resolve auto layout issues” and check “Update Frames”.
Now everything works in portrait and landscape