Original blog, reproduced please indicate the source
Blog.csdn.net/hello_hwc
Objective:
The previous article introduced some of the preparation knowledge to explain AutoLayout, this article continues to explain with storyboard to create AutoLayout. The next article will explain the use of code to create storyboard.
Create it in a Control+drag way
-For a view-relative superview constraint, drag the mouse control+ to Superview
-For two view, control+ mouse drag to another view
As an example:
I want to achieve this effect
The process is as follows
The first step
Drag a ImageView, follow the Blue Line reference to the View center, and then Control+drag to add two constraints to the ImageView to the center of the view in both horizontal and vertical directions.
The following motion diagram
Step Two
Control+drag this imageview to itself, adding a constant constraint of width and hight.
In this way, the imageview constraints are established. If a warning occurs after the establishment, you can select
Click Update Frames. Xcode will update the view frame for us according to the constraints.
The third step, drag two button, and then create the constraint, I want the button in the ImageView two corner. Note that you should follow the blue line when dragging.
The process follows the motion diagram
The same goes for Button2, and we're done with what we want.
Of course, Control+drag can create more than that, and the reader can drag and drop in the actual development process to find the desired constraint options.
Don't forget, you can also drag and drop in the outline.
This is especially useful when you have more than one view on the storyboard.
dragging to itself
Button1 Drag to Button2
Use some of Xcode's keys to create (recommended way)
This is the way I prefer, because the drag-and-drop method is sometimes difficult to drag.
These keys are in this position.
Then I use these keys to create the same constraints as above
Create a constraint for ImageView
- Let it in the View center
Select ImageView
- Add Height width unchanged
Select ImageView
- Add a constraint to Button1 to have a vertical distance of 8 from the ImageView (default control distance)
Select Button1
- Add a constraint to the Button1 to align it with the ImageView head
Check Button1 and ImageView
Similarly, for Button2 to it, but the Button2 alignment is the tail alignment, if a warning is present, the Updateframe
Finally, the function of each key is explained briefly.
The first one to handle alignment
Note that there are some pairs of Aceh two view, to select two view at a time
The part of the red circle is the description of the image.
The second processing distance information, such as the distance from the adjacent control is constant, the width is constant, for example, when the resize, two view height is consistent.
The third process, whether the control's current position and constraints are constrained to the same location as the update frame or update constraint, can also allow Xcode to automatically create
The fourth one is the constraint strategy when the view size changes.
Previous Tutorial AutoLayout Links
http://blog.csdn.net/hello_hwc/article/details/43967561
Finally, make a complaint: turn my blog comrade, do not forget to mark the source Ah!!! It's not easy to make a diagram!!
IOS AutoLayout Details (ii)-Detailed action diagram