zoukankan      html  css  js  c++  java
  • 分析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;
        };
    }
  • 相关阅读:
    YUM安装MySQL 8.0
    linux 设置 别名 全局命令
    2018.3.12校内互测总结-生成函数-bitset-二次剩余
    Dirichlet 前缀和与快速莫比乌斯变换(FMT)
    CSP-S2 赛后总结
    概率和期望
    【题解】[洛谷 P4396 / bzoj 3236] 作业【莫队 分块 根号平衡】
    【题解】[LOJ 2736] 「JOISC 2016 Day 3」回转寿司【分块 堆】
    【题解】[UOJ 228] 基础数据结构练习题【线段树 均摊数据结构】
    【题解】[Codeforces 438D] The Child and Sequence【线段树 均摊数据结构】
  • 原文地址:https://www.cnblogs.com/apem/p/4633092.html
Copyright © 2011-2022 走看看