文章概要
1.概要
最近這段時(shí)間有點(diǎn)忙沒過多的時(shí)間繼續(xù)寫技術(shù)博客,先寫個(gè)大綱過完這陣子再詳細(xì)補(bǔ)齊斩萌。
2.視圖大小自適應(yīng)(自動(dòng)約束下)-Intrinsic Content Size
3.Intrinsic Content Size 與 sizetofit
-(CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority
與
-(CGSize)intrinsicContentSize
之間的關(guān)系。
視圖內(nèi)容自適應(yīng)實(shí)現(xiàn)的一種方式:
-(void)layoutSubviews{
[super layoutSubviews];
if(!CGSizeEqualToSize(self.bounds.size, self.intrinsicContentSize)){
[self invalidateIntrinsicContentSize];//使系統(tǒng)調(diào)用intrinsicContentSize方法并且重新布局
}
}
-(CGSize)intrinsicContentSize{
return self.contentSize;
}
自動(dòng)約束系統(tǒng)
二、約束優(yōu)先級(jí)
約束優(yōu)先級(jí)的數(shù)值范圍是1~1000
,數(shù)值越高優(yōu)先級(jí)越高。
官方原文:
一種情況是我們經(jīng)常添加的各種約束,默認(rèn)的優(yōu)先級(jí)是1000佑惠,也就是最高級(jí)別也就是下面列舉的枚舉值
UILayoutPriorityRequired
.下面是我們常用的約束的幾個(gè)優(yōu)先級(jí):
typedef float UILayoutPriority NS_TYPED_EXTENSIBLE_ENUM;
static const UILayoutPriority UILayoutPriorityRequired NS_AVAILABLE_IOS(6_0) = 1000; // A required constraint. Do not exceed this.
static const UILayoutPriority UILayoutPriorityDefaultHigh NS_AVAILABLE_IOS(6_0) = 750; // This is the priority level with which a button resists compressing its content.
static const UILayoutPriority UILayoutPriorityDefaultLow NS_AVAILABLE_IOS(6_0) = 250; // This is the priority level at which a button hugs its contents horizontally.
static const UILayoutPriority UILayoutPriorityFittingSizeLevel NS_AVAILABLE_IOS(6_0) = 50; // When you send -[UIView systemLayoutSizeFittingSize:], the size fitting most closely to the target size (the argument) is computed. UILayoutPriorityFittingSizeLevel is the priority level with which the view wants to conform to the target size in that computation. It's quite low. It is generally not appropriate to make a constraint at exactly this priority. You want to be higher or lower.
優(yōu)先級(jí)如下:
UILayoutPriorityRequired > UILayoutPriorityDefaultHigh > UILayoutPriorityDefaultLow > UILayoutPriorityFittingSizeLevel
二、Intrinsic Content Size
3.1 Intrinsic Content Size Versus Fitting Size
官方文件地址:Anatomy of a Constraint
參考文獻(xiàn):
Auto Layout Guide (官方文檔)
iOS開發(fā)-LayoutGuide的前世今生(從top/bottom LayoutGuide到Safe Area)