autoresizingMask是UIView的屬性十绑,該屬性的作用是調(diào)整子視圖的上、下酷勺、左本橙、右邊距及寬高,以保證子視圖相對與父視圖的位置鸥印。autoresizingMask的值對應(yīng)一個(gè)枚舉勋功,默認(rèn)值是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
};
值分析:
UIViewAutoresizingNone:表示不隨父視圖的改變而改變
UIViewAutoresizingFlexibleLeftMargin:表示隨著父視圖的改變自動調(diào)整view與父視圖的左邊距库说,保證view與父視圖的右邊距不變狂鞋;
UIViewAutoresizingFlexibleWidth:表示隨著父視圖的改變自動調(diào)整view的寬度,保證view與父視圖左右邊距不變潜的;
UIViewAutoresizingFlexibleRightMargin:表示隨著父視圖的改變自動調(diào)整view與父視圖的右邊距骚揍,保證view與父視圖的左邊距不變;
UIViewAutoresizingFlexibleTopMargin:表示隨著父視圖的改變自動調(diào)整view與父視圖的上邊距啰挪,保證下邊距不變信不;
UIViewAutoresizingFlexibleHeight:表示隨著父視圖的改變自動調(diào)整view的高度,保證view與父視圖的上下邊距不變亡呵;
UIViewAutoresizingFlexibleBottomMargin:表示隨著父視圖的改變自動調(diào)整view與父視圖的下邊距抽活,保證上邊距不變;
實(shí)際開發(fā)中锰什,我們可以根據(jù)需要組合使用上述幾種枚舉值下硕,各個(gè)值用‘|’隔開丁逝,如下:
self.overView.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
這句代碼的意思是,自動調(diào)整self.overView的寬高保證self.overView與父視圖的左右邊距和上下邊距不變梭姓;