看一下Masonry支持哪一些屬性
@property(nonatomic,strong,readonly) MASConstraint *left;
@property(nonatomic,strong,readonly) MASConstraint *top;
@property(nonatomic,strong,readonly) MASConstraint *right;
@property(nonatomic,strong,readonly) MASConstraint *bottom;
@property(nonatomic,strong,readonly) MASConstraint *leading;
@property(nonatomic,strong,readonly) MASConstraint *trailing;
@property(nonatomic,strong,readonly) MASConstraint *width;
@property(nonatomic,strong,readonly) MASConstraint *height;
@property(nonatomic,strong,readonly) MASConstraint *centerX;
@property(nonatomic,strong,readonly) MASConstraint *centerY;
@property(nonatomic,strong,readonly) MASConstraint *baseline;
這些屬性與NSLayoutAttrubute的對照表如下:
首先在Masonry中能夠添加autolayout約束有三個函數(shù)
- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
mas_makeConstraints只負(fù)責(zé)新增約束Autolayout不能同時(shí)存在兩條針對于同一對象的約束,否則會報(bào)錯逐沙。
mas_updateConstraints針對上面的情況會更新在block中出現(xiàn)的約束不會導(dǎo)致出現(xiàn)兩個相同約束的情況欧穴。
mas_remakeConstraints則會清除之前的所有約束僅保留最新的約束。
三種函數(shù)善加利用就可以應(yīng)對各種情況了
非常好的一篇Masonry的文章