本章大致描述一下Masonry是如何支持鏈?zhǔn)秸Z法的亿鲜,并且對框架的其他一些文件做一些描述
第一部分 了解一下鏈?zhǔn)秸Z法是如何實(shí)現(xiàn)的###
實(shí)際上前面兩篇文章已經(jīng)講述的差不多了寇漫,如果看過源碼例嘱,應(yīng)該就會很輕松的知道,Masonry是如何支持鏈?zhǔn)秸Z法的結(jié)構(gòu)。
還是拿一個(gè)例子的講解一下吧,(下方代碼已刪除不甚相關(guān)的代碼)
make.top.left究竟發(fā)生了什么际看?
我們知道m(xù)ake.top返回的是MASConstraint對象,更確切的說是MASViewConstraint對象矢否,
上篇文章中我們知道仲闽,對MASConstraint調(diào)用top、left等僵朗,會返回一個(gè)MASCompositeConstraint對象赖欣;
這個(gè)對象,會包含一個(gè)數(shù)組验庙,在這個(gè)例子中存放的就是layoutAttribute分別為top和left的
兩個(gè)MASViewConstraint對象顶吮。
1、MASConstraint的left方法:
- (MASConstraint *)left {
return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
}
它會跳轉(zhuǎn)到MASViewConstraint的addConstraintWithLayout...方法
--------------------------------------------
2粪薛、MASViewConstraint的addConstraintWithLayout...方法
- (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
return [self.delegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
}
它會調(diào)用delegate的constraint...delegate就是MASConstraintMaker悴了,來看看吧
--------------------------------------------
3、MASConstraintMaker的代理方法
- (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
[self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint];
return compositeConstraint;
}
第二部分 一些Category###
??1汗菜、NSArray (MASAdditions)
array內(nèi)部是view让禀,遍歷array,逐一對view調(diào)用這些方法
- (NSArray *)mas_makeConstraints:(void (^)(MASConstraintMaker *make))block;
- (NSArray *)mas_updateConstraints:(void (^)(MASConstraintMaker *make))block;
- (NSArray *)mas_remakeConstraints:(void (^)(MASConstraintMaker *make))block;
2陨界、View+MASAdditions
我們平時(shí)巡揍,也可以對view調(diào)用一些方法例如:
@property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
可以看到,返回的是MASViewAttribute對象
剩下的就是比較簡單的mas_makeConstraint...
3菌瘪、ViewController+MASAdditions
@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom;
這些就是對齊self.view的頂部導(dǎo)航欄和底步tabbar的頂部了腮敌,底部之類的