Autoresizing: As early as possible, only constraints on the parent control (note: To turn off autolayout&size classes to see autoresizing)
Code corresponds to:
The Autoresizingmask property in UIView.h
@property (nonatomic) uiviewautoresizing autoresizingmask; Simple resize. Default is Uiviewautoresizingnone
typedef ns_options (Nsuinteger, uiviewautoresizing) {
Uiviewautoresizingnone = 0,
Uiviewautoresizingflexibleleftmargin = 1 << 0,
Uiviewautoresizingflexiblewidth = 1 << 1,
Uiviewautoresizingflexiblerightmargin = 1 << 2,
Uiviewautoresizingflexibletopmargin = 1 << 3,
Uiviewautoresizingflexibleheight = 1 << 4,
Uiviewautoresizingflexiblebottommargin = 1 << 5
};
AutoLayout: Not only is it possible to constrain the parent control, but it can also be constrained for peers, but it depends on the screen of different devices
Size classes: Divides all dimensions into regular (standard) compact (compact) any (arbitrary) three case combinations, no longer dependent on the dead size, which effectively solves the disadvantage of AutoLayout
Size classes:
But we see that the width and height of the graph are all Any
, what does any mean? If weight
set to Any
, height
then the Regular
interface element in that state will exist in the state as long as it is height
Regular
present, both in and out weight
Regular
Compact
. This relationship should be called an inheritance relationship, and the specific four interface descriptions and inheritable interfaces are described below:
- W:compact h:compact Inheritance (w:any h:compact , w:compact h:any , w:any h:any)
- W:regular h:compact Inheritance (w:any h:compact , w:regular h:any , w:any h:any)
- W:compact h:regular Inheritance (w:any h:regular , w:compact h:any , w:any h:any)
- W:regular h:regular Inheritance (w:any h:regular , w:regular h:any , w:any h:any)
We know that iOS 8 the device interface below can be described as 4, but what exactly is the description of so many devices (Iphone4s,iphone5/5s,iphone6,iphone6 plus,ipad,apple Watch)? After reviewing official documentation and specific practices, the specific correspondence is as follows:
- Iphone4s,iphone5/5s,iphone6
- Vertical screen: (w:compact h:regular)
- Horizontal screen: (w:compact h:compact)
- IPhone6 Plus
- Vertical screen: (w:compact h:regular)
- Horizontal screen: (w:regular h:compact)
- Ipad
- Vertical screen: (w:regular h:regular)
- Horizontal screen: (w:regular h:regular)
- Apple Watch (guess)
- Vertical screen: (w:compact h:compact)
- Horizontal screen: (w:compact h:compact)
Code Correspondence: Uitraitcollection
UIViewController.h
-(void) Willtransitiontotraitcollection: (uitraitcollection *) newcollection withtransitioncoordinator: (ID < uiviewcontrollertransitioncoordinator>) Coordinator Ns_available_ios (8_0);
UITraitCollection.h (normal view)
/*! Trait environments expose a Trait collection that describes their environment. */
@protocol uitraitenvironment <NSObject>
@property (nonatomic, readonly) uitraitcollection *traitcollection;
/*! To being overridden as needed to provide custom behavior when the environment's traits change. */
-(void) Traitcollectiondidchange: (uitraitcollection *) previoustraitcollection;
@end
AutoLayout:
Code corresponds to:
Nslayoutconstraint
Note: Hand code auto layout turns off the following properties of UIView first
1.-(BOOL) translatesautoresizingmaskintoconstraints Ns_available_ios (6_0); Default YES
2.1VFL language
+ (Nsarray *) Constraintswithvisualformat: (NSString *) format options: (nslayoutformatoptions) OPTs metrics: ( Nsdictionary *) Metrics Views: (Nsdictionary *) views;
2.2 Pure Code
+ (Instancetype) Constraintwithitem: (id) view1 attribute: (nslayoutattribute) attr1 Relatedby: (nslayoutrelation) Relation Toitem: (id) view2 attribute: (nslayoutattribute) attr2 multiplier: (cgfloat) Multiplier constant: (cgfloat) C;
Details: http://www.cnblogs.com/zhw511006/p/3998534.html
IOS autoresizing AutoLayout Size Classes