1, automatic layout is a constraint-based layout (constraint-based layouts) engine that automatically adjusts the size and position based on the developer's constraints on the object.
2. The layout model used prior to iOS 6 is the "spring&struts" model. While running efficiently in most cases, you still need to write code to customize the layout for a child view when you rotate.
3. The layout code is written in the Layousubviews method.
4. The first noticeable change when using automatic layout in Xcode 5 is that Xcode 5 does not automatically add constraints unless you explicitly require Xcode to add.
Xcode 5 lets developers control the layout without automatically adding constraints.
If you add a constraint that does not define the layout, Xcode 5 's Storyboard or interface Builder compiler generates a warning and fixes suggestions.
In Xcode 5, if no constraints are added, the IDE automatically adds fixed location and size constraints at run time.
5. Using automatic layout in Xcode 5
To open the storyboard, you can see the following four buttons:
Align (first): Used to add alignment constraints.
Pin (): Adds standard constraints, such as size and position relative to other views.
Reslove (resolution) Auto Layout issues (case): You can have Xcode automatically generate constraints, or update the frame based on the constraint's view to the correct location.
Resizing Behavior: Can be used to set which classes inherit these constraints. By default, siblings and ancestors (siblings and ancestors) and descendants (descendants) are selected. But it is recommended to leave silbings and ancestors blank. If checked, it becomes difficult to align the sub-views in the view, where the origin of the child view is fixed, and when you set the size of the child view, the ancestor view changes, which is annoying. When you create a layout, you use the other three menu buttons.
6. Intrinsic dimensions
Most control elements in iOS have intrinsic dimensions. Open the Dimensions View panel (size inspector) and you will find that some properties (eg: height and width) cannot be modified.
7. Intrinsic size and localization
The intrinsic dimensions of Uilabel and UIButton are interesting. The intrinsic size reflects its content, the longer the title, the wider the intrinsic size of the label, and the ability to create a button and label that automatically adjusts the size according to the internal dimensions of the different languages with automatic layout.
8. Design-time and run-time layouts
Xcode 5 does not automatically add constraints. Conversely, if you add a constraint that does not have an ambiguous description of the layout, Xcode 5 displays a series of warnings or errors, and highlights the ambiguity in the layout.
In most cases, any situation that causes the user interface to be incorrectly laid out will produce a warning and the run-time crash (mainly caused by ambiguous constraints) is considered an error. at design time (that is, the design phase, relative to the runtime), the problematic controls are in a yellow solid line, and the controls that run with the problem are in a dashed red box.
The yellow box highlights the problematic control, displays its size and position at design time, and the red box shows its size and position at run time.
Instead of adding the missing constraint manually, click the Third menu button and choose "Add Missing Constraints" to have Xcode add it automatically.
9. Automatically update borders
A warning appears as follows when a view is not in the wrong place:
You can eliminate this warning by clicking the third button and selecting Update frames.
10. Top and Bottom layout guide
In iOS 7, each view controller has two properties, called Toplayoutguide and Bottomlayoutguide. Xcode 5 Displays it as an object in the IB document. We can align the view with these two properties.
11. Layout Preview in the auxiliary editor
The auxiliary editor for Xcode 5 also provides a preview of the user interface, simulating iOS 6 and iOS 7 devices, as well as horizontal and vertical screens. Just open the Auxiliary editor, click the first button in the top-level path navigation bar Menu , select Preview, and you'll see a preview of the user interface in the secondary editor panel. The preview panel is updated in real time as the document is modified.
12. Debugging automatic layouts at design time
Xcode 5 Debug Auto layout is much easier than ever before, and can only run apps on a variety of devices and then crash. Xcode 5 allows developers to visually handle these crashes at design time. The light is a huge improvement on the workflow.
There are two main types of problems with automatic layout, the first of which occurs when the constraint set is not sufficient to define all the possible screen orientations/dimensions of the layout. The second category is that too many constraints occur when at least one screen orientation creates a conflict.
The first type of problem can be broadly divided into two types, border ambiguity and view placement errors . When you do not add a constraint to unambiguously determine the position and size of the view at run time, a border ambiguity occurs. View placement errors are side effects of border ambiguity. The size and position of the design-time view may not match the size and position of the runtime, which is where Xcode warns of incorrect view placement. It is common to add the necessary constraints to solve this problem.
As the name implies, constraint collisions occur when the added constraints conflict with each other, and at this point the automatic layout engine attempts to break the constraints at run time (and print a message listing the broken constraints) and layout, and if the failure results in a run-time crash. Constraint conflicts are the only layout errors that cannot be found at design time. In some cases, the constraints are in some kind of screen direction conflict, you may add the constraints in the case of a vertical screen work well, to the horizontal screen situation but conflict.
13. Use scrolling view in automatic layout
14. Use automatic layout and borders
15. Visual format language and its disadvantages
16. Debug Layout Error
The Debug table log lists the constraints for automatic layout.
Mastering iOS Auto-layout