Masonry 参考笔记
Masonry https://github.com/Masonry/Masonry
[_testView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(_testView.superview)
}];
@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;
mas_equalTo() 和 equalTo()
mas_equalTo() 只是对其参数进行了一个BOX操作(装箱) 所支持的类型 除了NSNumber支持的那些数值类型之外 就只支持CGPoint CGSize UIEdgeInsets
mas_equalTo() 官方demo中 发现 mas_equalTo() 参数是明确的数值,要转化为NSNumber类型。
equalTo() 用于和supview 或者和其他view 相比较
make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));
/* 等价于
make.top.equalTo(self).with.offset(10);
make.left.equalTo(self).with.offset(10);
make.bottom.equalTo(self).with.offset(-10); 计算的bottom需要小于sv的底部高度 所以要-10
make.right.equalTo(self).with.offset(-10); 同理
*/
/* 也等价于
make.top.left.bottom.and.right.equalTo(self).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));
*/
edges 其实就是top,left,bottom,right的一个简化
- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
mas_makeConstraints 只负责新增约束 Autolayout不能同时存在两条针对于同一对象的约束 否则会报错
mas_updateConstraints 针对上面的情况 会更新在block中出现的约束 不会导致出现两个相同约束的情况
mas_remakeConstraints 则会清除之前的所有约束 仅保留最新的约束
masonry中 有and 和 with 用法: and 多个并列属性 with 添加附带条件

浙公网安备 33010602011771号