Lachlan Reid
Lachlan Reid

Reputation: 11

Is Xcode 7 auto layout broken or just difficult to use

Since moving to Xcode 7 I am receiving a lot of warnings that I didn't get in Xcode 6 - "Frame for -text field- will be different at run time".

I have followed all of the suggested resolutions based on "Resolve auto layout issues" but that actually breaks the layout that I had established with objects no longer positioned where I want them. It seems to me to be a bug.

In order to test this I created a new VC and added a label, button and text field. For the button and label I set constraints to establish the vertical position, then fixed height and width and finally Horizontally centre on container. This is how I have always used auto layout and it works correctly showing blue constraints and no errors or warnings. The problem is the text field which I have stretched to the left and right guidelines of the VC. For this I add vertical, left and right constraints and fixed height and I am left with a warning that - 'Frame for "Round Style Text Field" will be different at run time.' I'm not doing anything complex here, simply using auto layout they way I have consistently used it in previous versions of Xcode. So I can only see the following possibilities:

  1. Its a bug and not working correctly. It is tied to an Xcode guideline and yet is 4 units out of position... why?
  2. The way I have always used auto layout is no longer supported and I need to use it differently. When I use reset to suggested constraints it removes the right hand constraint and replaces it with a centre constraint to align with the button above it. I don't understand how these suggested constraints work and so wouldn't think to do it this way myself.
  3. Its no longer possible to apply constraints normally without letting Xcode do it for you? When I have had problems in the past I have simply cleared constraints and re-applied them and it has always worked. Now I cannot apply constraints myself successfully even with this very simple test VC!!

I get the impression that most people find auto-layout has problems and as a result very few people are using it, but unless we get to the bottom of problems like this it will just continue. I am frustrated with what appears to be a arbitrary change to the way auto-layout works. Before i report as a bug I would like to get views from other people with experience in auto-layout.

Upvotes: 0

Views: 540

Answers (1)

Duncan C
Duncan C

Reputation: 131398

Interface builder is rather schizophrenic with AutoLayout. It maintains 2 largely independent settings on your views: Their frames, and their constraints. The frames are ignored at runtime and overridden by the constraints.

If the views' frames don't match the frames that would result from applying the constraints, you get the warnings that you are getting.

To fix it, use the editor menu>Resolve Auto Layout Issues>Update Frames. (The "Resolve Auto Layout Issues" commands are also available from the triangle icon, as Gandalf mentions in his comment.)

That adjusts the sizes and positions of your views to match the constraints you've set.

The "reset to suggested constraints" command does the opposite, and discards and replaces your constraints based on (I think) the positions of the views. I have never found this useful. I would say it's best avoided once you've started setting constraints.

Upvotes: 1

Related Questions