分析Masonry

一. 继承关系

1.MASConstraint (abstract)

MASViewContraint    MASComposisionConstraint

 

2. UIView      NSLayoutConstraint

MAS_View     MASLayoutConstraint

 

3. MASViewConstrant MASViewAttribute

二. 包含关系

MASViewContraint继承与MASConstraint

拥有 两个MASViewAttribute *属性

@property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute;

@property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute;

MASViewContraint是整个Masonry框架的核心

拥有MASConstraint的所有属性和方法,并必须重写MASConstraint的抽象方法

具体有以下, 主要的功能是包装MASConstraint并设置进入MASConstraintMaker的constrains数组中, 

 

- (MASConstraint *)left;

- (MASConstraint *)top;

- (MASConstraint *)right;

- (MASConstraint *)bottom;

- (MASConstraint *)leading;

- (MASConstraint *)trailing;

- (MASConstraint *)width;

- (MASConstraint *)height;

- (MASConstraint *)centerX;

- (MASConstraint *)centerY;

- (MASConstraint *)baseline;

 

#if TARGET_OS_IPHONE

 

- (MASConstraint *)leftMargin;

- (MASConstraint *)rightMargin;

- (MASConstraint *)topMargin;

- (MASConstraint *)bottomMargin;

- (MASConstraint *)leadingMargin;

- (MASConstraint *)trailingMargin;

- (MASConstraint *)centerXWithinMargins;

- (MASConstraint *)centerYWithinMargins;

 

#endif

 

每个MASViewAttribute拥有 一个MAX_View属性 和一个 NSLayoutAttribute属性

@property (nonatomic, weak, readonly) MAS_VIEW *view;

@property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute;

 

MASConstraintMaker 作为MASViewContraintDelegate的委托接收者, 主要负责收集MASViewContraint进入constraints数组属性, 以及安装constraints数组内的约束

@property (nonatomic, weak) MAS_VIEW *view;

@property (nonatomic, strong) NSMutableArray *constraints;

 

定义必须要被重写否则会抛出异常方法

#define MASMethodNotImplemented() \
    @throw [NSException exceptionWithName:NSInternalInconsistencyException \
                                   reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \
                                 userInfo:nil]

 

定义类似其他语言(如Java/C#)的方法调用

- (MASConstraint * (^)(NSValue *value))valueOffset {
    return ^id(NSValue *offset) {
        NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset);
        [self setLayoutConstantWithValue:offset];
        return self;
    };
}

 

转载于:https://www.cnblogs.com/apem/p/4633092.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值