一丶 Autoresizing
1.1 摘要: 蘋果在iOS2中引入了Autoresizing技術用于屏幕適配, 用于在其父視圖的bounds發生改變時如何自動調整如何調整自身布局(大小)
1.2 使用:
-
?? Autoreszing 與 Auto Layout 二者不能共存,Xcode中默認開啟了Autolayout技術, 在使用Autoresizing技術前需要手動將其關閉
關閉Auto Layout.png - autoresizingMask屬性: autoresizingMask屬性的設置由六根線標識, 其中位于外部的四根線分別用于標識用于父視圖的bounds發生改變時自動調整與父視圖的上、下、左、右邊距; 位于內部的兩根線分別用于標識如何自動調整自身的寬度和高度
-
默認autoresizingMask標識的情況下autoresizingMask屬性.png默認autoresizingMask標識.jpg
-
設置autoresizingMask距離父視圖的右邊與底部的標識距離父視圖的右邊與底部的標識.png效果圖
-
設置autoresizingMask自動調整自身的寬度和高度
距離父視圖的右邊與底部的標識.png
自動調整自身的寬度和高度效果圖.png 代碼實現
/*
UIViewAutoresizingNone = 0, //不會根據父控件的改變而進行改變
UIViewAutoresizingFlexibleLeftMargin = 1 << 0, 自動調整距離父控件左邊邊距(也就是距離右邊邊距是固定的)
UIViewAutoresizingFlexibleWidth = 1 << 1, 自動調整寬度根據父控件的寬度發生變化而變化
UIViewAutoresizingFlexibleRightMargin = 1 << 2, 自動調整距離父控件u右邊邊距
UIViewAutoresizingFlexibleTopMargin = 1 << 3, 自動調整距離父控件頂部邊距
UIViewAutoresizingFlexibleHeight = 1 << 4, 自動調整高度根據父控件的高度發生變化而變化
UIViewAutoresizingFlexibleBottomMargin = 1 << 5 自動調整距離父控件底部邊距
*/
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];