autoresizingMask属性的简介
autoresizingMask是UIView的属性,该属性的作用是调整子视图的上、下、左、右边距及宽高,以保证子视图相对与父视图的位置。autoresizingMask的值对应一个枚举,默认值是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:表示随着父视图的改变自动调整view与父视图的左边距,保证view与父视图的右边距不变;
UIViewAutoresizingFlexibleWidth:表示随着父视图的改变自动调整view的宽度,保证view与父视图左右边距不变;
UIViewAutoresizingFlexibleRightMargin:表示随着父视图的改变自动调整view与父视图的右边距,保证view与父视图的左边距不变;
UIViewAutoresizingFlexibleTopMargin:表示随着父视图的改变自动调整view与父视图的上边距,保证下边距不变;
UIViewAutoresizingFlexibleHeight:表示随着父视图的改变自动调整view的高度,保证view与父视图的上下边距不变;
UIViewAutoresizingFlexibleBottomMargin:表示随着父视图的改变自动调整view与父视图的下边距,保证上边距不变;
实际开发中,我们可以根据需要组合使用上述几种枚举值,各个值用‘|’隔开,如下:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
这句代码的意思是,自动调整self.view的宽高保证self.overView与父视图的左右边距和上下边距不变;