[quote=194205:@John Fatte]Does anyone else thing that the auto-layout in IOS is way too flakey to rely on?
I get a view all laid out the way I want and then want to move one control to a new location and everything goes out of whack. That control may jump to the top of the screen or the auto-layout settings will change on their own.[/quote]
Auto Layout is here to help you but as anything computer, you got to teach the robot.
The layout editor tries to guess where you want to place the control, but instead of doing like the Desktop of Web one, it assumes a bit too much and ends up wrong.
Let us say you drag a canvas in the center of the screen, some 1/3 away from the top.
The constraints end up as
H.Center = Parent.CenterX
Height = 200
Top = 70
Width = 200
Auto Layout did pretty much the same as what would have happened in Desktop, except the canvas is horizontally centered. If you rotate the device, it will be smack in the center no matter what.
For each control, look in the Inspector at the constraints. If what you want is ‘the old way’, then instead you can go
Left = Parent.Left*0%+70
Height = 200
Top = 70
Width = 200
That way you are sure the control will not jump on you. But if you rotate, no auto layout, the canvas will stay on the left of the screen.
Sometimes the layout editor gets it wrong, especially when there are several controls on the view. Let us say you place a button under the canvas.
Without anything, here is what happens :
H.Center = Parent.centerX
Height = 30
Top = 343
Width = 100
That works fairly well in case of rotation to keep the button in the center, but on an iPHone 5, 343 is far too low and the button will be off screen.
Typical Auto Layout way is to make it relative not to the top, but to the bottom of the screen, change Top to
Top = Parent.Bottom-150
So when the device rotates, the button does not disappear.
The tricky part is to wrap your head around the fact that you can “hang” the control to the top and the left of the screen, but also to its bottom, to its left, or to another control. For instance :
Top = Canvas1.Bottom-+20
As you see, you can completely turn off Auto Layout as you wished by using constraints “the old way”, or take advantage of Auto Layout way of making a control relative to any other part of the view.
The IDE does its best to assume what you are after, but you must check all constraints carefully to avoid controls jumping around.