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

相關文章
相關標籤/搜索