iOS Autoresizing Autolayout Size classes

Autoresizing:出现最先,仅仅可以针对父控件作约束(注意:要关闭Autolayout&Size classes才可以看到Autoresizing)html

代码对应:ide

UIView.h中的autoresizingMask属性布局

@property(nonatomic) UIViewAutoresizing autoresizingMask;    // simple resize. default is UIViewAutoresizingNoneatom

typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {code

    UIViewAutoresizingNone                 = 0,orm

    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,htm

    UIViewAutoresizingFlexibleWidth        = 1 << 1,blog

    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,继承

    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,ip

    UIViewAutoresizingFlexibleHeight       = 1 << 4,

    UIViewAutoresizingFlexibleBottomMargin = 1 << 5

};

 

Autolayout:不单单可以针对父控件约束,并且能够针对同级进行约束,但对不一样设备的横竖屏仍是有依赖

Size classes:将全部尺寸分为Regular(标准的)compact(紧凑的) any(任意的)三种状况 进行组合,再也不依赖于死的尺寸,这就有效解决了Autolayout的弊端

Size classes:

可是咱们看到图中的宽度和高度都是Any,Any是什么意思呢?若是weight设为Anyheight设置为Regular,那么在该状态下的界面元素在只要heightRegular,不管weightRegular仍是Compact的状态中都会存在。这种关系应该叫作继承关系,具体的四种界面描述与可继承的界面描述以下:

  • w:Compact h:Compact 继承 (w:Any h:Compact , w:Compact h:Any , w:Any h:Any)
  • w:Regular h:Compact 继承 (w:Any h:Compact , w:Regular h:Any , w:Any h:Any)
  • w:Compact h:Regular 继承 (w:Any h:Regular , w:Compact h:Any , w:Any h:Any)
  • w:Regular h:Regular 继承 (w:Any h:Regular , w:Regular h:Any , w:Any h:Any)

咱们知道了iOS 8下面设备界面能够描述为4种,可是这么多设备(iPhone4S,iPhone5/5s,iPhone6,iPhone6 Plus,iPad,Apple Watch)具体对应什么描述呢?通过查看官方文档和具体实践得知具体对应关系以下:

  • iPhone4S,iPhone5/5s,iPhone6
    • 竖屏:(w:Compact h:Regular)
    • 横屏:(w:Compact h:Compact)
  • iPhone6 Plus
    • 竖屏:(w:Compact h:Regular)
    • 横屏:(w:Regular h:Compact)
  • iPad
    • 竖屏:(w:Regular h:Regular)
    • 横屏:(w:Regular h:Regular)
  • Apple Watch(猜想)
    • 竖屏:(w:Compact h:Compact)
    • 横屏:(w:Compact h:Compact)

代码对应:UITraitCollection

UIViewController.h

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);

UITraitCollection.h(普通View)

/*! Trait environments expose a trait collection that describes their environment. */

@protocol UITraitEnvironment <NSObject>

@property (nonatomic, readonly) UITraitCollection *traitCollection;

 

/*! To be overridden as needed to provide custom behavior when the environment's traits change. */

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection;

@end

Autolayout:

代码对应: 

NSLayoutConstraint

注意:手码自动布局先关闭UIView的如下属性

1.- (BOOL)translatesAutoresizingMaskIntoConstraints NS_AVAILABLE_IOS(6_0); // Default YES

2.1VFL语言

+ (NSArray *)constraintsWithVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views;

2.2纯粹代码 

+(instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c;

 

 

 

详情:http://www.cnblogs.com/zhw511006/p/3998534.html

相关文章
相关标签/搜索