/*
UIViewAutoresizingNone = 0, /// 不隨父視圖的改變而改變
UIViewAutoresizingFlexibleLeftMargin = 1 << 0, /// 自動調(diào)整view與父視圖左間距御毅,保證右間距不變
UIViewAutoresizingFlexibleWidth = 1 << 1, /// 自動調(diào)整view的寬度端蛆,保證左間距和右間距不變
UIViewAutoresizingFlexibleRightMargin = 1 << 2, /// 自動調(diào)整view與父視圖右間距欺税,以保證左間距不變
UIViewAutoresizingFlexibleTopMargin = 1 << 3, /// 自動調(diào)整view與父視圖上間距,以保證下間距不變
UIViewAutoresizingFlexibleHeight = 1 << 4, /// 自動調(diào)整view的高度亭罪,以保證上間距和下間距不變
UIViewAutoresizingFlexibleBottomMargin = 1 << 5 /// 自動調(diào)整view與父視圖的下間距歼秽,以保證上間距不變
*/
測試代碼如下
- (void)viewDidLoad {
[super viewDidLoad];
UIView *redView = [[UIView alloc] init];
self.redView = redView;
[self.view addSubview: redView];
redView.frame = CGRectMake(100, 100, 300, 300);
redView.backgroundColor = [UIColor redColor];
UIView *blueView = [[UIView alloc] init];
[redView addSubview:blueView];
blueView.backgroundColor = [UIColor blueColor];
blueView.frame = CGRectMake(50, 50, 100, 100);
blueView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
NSLog(@"%ld",self.view.autoresizingMask);
NSLog(@"---%d",1 << 1 | 1 << 4);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
CGRect f = self.redView.frame;
f.size.width +=5;
f.size.height +=5;
self.redView.frame = f;
}