一丶 Autoresizing
1.1 摘要: 蘋果在iOS2中引入了Autoresizing技術(shù)用于屏幕適配, 用于在其父視圖的bounds發(fā)生改變時如何自動調(diào)整如何調(diào)整自身布局(大小)
1.2 使用:
-
?? Autoreszing 與 Auto Layout 二者不能共存邀跃,Xcode中默認(rèn)開啟了Autolayout技術(shù), 在使用Autoresizing技術(shù)前需要手動將其關(guān)閉
關(guān)閉Auto Layout.png - autoresizingMask屬性: autoresizingMask屬性的設(shè)置由六根線標(biāo)識, 其中位于外部的四根線分別用于標(biāo)識用于父視圖的bounds發(fā)生改變時自動調(diào)整與父視圖的上、下报腔、左蛇更、右邊距; 位于內(nèi)部的兩根線分別用于標(biāo)識如何自動調(diào)整自身的寬度和高度
-
默認(rèn)autoresizingMask標(biāo)識的情況下autoresizingMask屬性.png默認(rèn)autoresizingMask標(biāo)識.jpg
-
設(shè)置autoresizingMask距離父視圖的右邊與底部的標(biāo)識距離父視圖的右邊與底部的標(biāo)識.png效果圖
-
設(shè)置autoresizingMask自動調(diào)整自身的寬度和高度
距離父視圖的右邊與底部的標(biāo)識.png
自動調(diào)整自身的寬度和高度效果圖.png 代碼實現(xiàn)
/*
UIViewAutoresizingNone = 0, //不會根據(jù)父控件的改變而進行改變
UIViewAutoresizingFlexibleLeftMargin = 1 << 0, 自動調(diào)整距離父控件左邊邊距(也就是距離右邊邊距是固定的)
UIViewAutoresizingFlexibleWidth = 1 << 1, 自動調(diào)整寬度根據(jù)父控件的寬度發(fā)生變化而變化
UIViewAutoresizingFlexibleRightMargin = 1 << 2, 自動調(diào)整距離父控件u右邊邊距
UIViewAutoresizingFlexibleTopMargin = 1 << 3, 自動調(diào)整距離父控件頂部邊距
UIViewAutoresizingFlexibleHeight = 1 << 4, 自動調(diào)整高度根據(jù)父控件的高度發(fā)生變化而變化
UIViewAutoresizingFlexibleBottomMargin = 1 << 5 自動調(diào)整距離父控件底部邊距
*/
CGFloat H = [UIScreen mainScreen].bounds.size.height;
CGFloat W = [UIScreen mainScreen].bounds.size.width;
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(W-100, H-100, 100, 100)];
blueView.backgroundColor = [UIColor blueColor];
blueView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:blueView];