一. 继承关系

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;
};
}

分析Masonry的更多相关文章

  1. iOS开发之Masonry框架源码深度解析

    Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...

  2. Masonry框架源码深度解析

    Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...

  3. iOS开发之Masonry框架源码解析

    Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...

  4. Masonry与UITableView+FDTemplateLayoutCell搭配使用

    打个小广告:本人开发了一个宠物相关的App,欢迎大家下载体验~ 下载二维码: 进入正文: 之前发过一篇博客,也是对这两个的练习使用,但是之后遇到些问题,所以删除重写了.抱歉 Masonry是一款轻量级 ...

  5. 【原】Masonry+UIScrollView的使用注意事项

    [原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...

  6. 【转】有趣的Autolayout示例-Masonry实现

    原文网址:http://tutuge.me/2015/05/23/autolayout-example-with-masonry/ 好久没有写Blog了,这段时间有点忙啊=.=本文举了3个比较有“特点 ...

  7. iOS开发 masonry 设置tableHeadView

    最近做公司项目,使用到到tableHeadView,一直习惯用masonry来设置约束,但是设置tableHeadView没有那么的简单.先看下效果图: 视图层次结构是这样的: 基础的创建工程项目之类 ...

  8. 【HELLO WAKA】WAKA iOS客户端 之一 APP分析篇

    由于后续篇幅比较大,所以调整了内容结构. 全系列 [HELLO WAKA]WAKA iOS客户端 之一 APP分析篇 [HELLO WAKA]WAKA iOS客户端 之二 架构设计与实现篇 [HELL ...

  9. IOS控件布局之Masonry布局框架

    前言: 回想起2013年做iOS开发的时候,那时候并没有采用手写布局代码的方式,而是采用xib文件来编写,如果使用纯代码方式是基于window的size(320,480)计算出一个相对位置进行布局,那 ...

随机推荐

  1. java编程思想-接口总结

    "确定接口是理想选择,因而应该总是选择接口而不是具体的类."这其实是一种诱饵.当然,对于创建类,几乎在任何时刻,都可以替代为创建一个接口和一个工厂. 许多人都掉进了这种诱惑的陷阱, ...

  2. JAVA 自定义状态码

    返回信息类(ResponseInfo): public class ResponseInfo { public static final String Status = "status&qu ...

  3. [转]h5页面测试总结

    转自http://www.blogjava.net/qileilove/archive/2014/07/24/416154.html?utm_source=tuicool H5页面测试总结 其实经过几 ...

  4. 加载信息,先从数据库取出5条实现分页,鼠标向上滑动触发Ajax再加载5条,达到异步刷新,优化加载。。。

    php数据库取数据 <?php include("conn1.php"); include('../function/functions.php'); $page=intva ...

  5. CodeForces 716A Crazy Computer

    题目链接:http://codeforces.com/problemset/problem/716/A 题目大意: 输入 n c, 第二行 n 个整数,c表示时间间隔 秒. 每个整数代表是第几秒.如果 ...

  6. Java Native Interface Specification

    http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html http://www.ibm.com/develo ...

  7. js随机生成N位数

    function RondomPass(number){ var arr = new Array; "); ;i<number;i++){ ); arr[i] =arr1[n] ; / ...

  8. MySQL取每组的前N条记录

    一.对分组的记录取前N条记录:例子:取前 2条最大(小)的记录 .用子查询: SELECT * FROM right2 a WHERE > (SELECT COUNT(*) FROM right ...

  9. 二、oracle pctfree和pctused详解

    一.建立表时候,注意PCTFREE参数的作用 PCTFREE:为一个块保留的空间百分比,表示数据块在什么情况下可以被insert,默认是10,表示当数据块的可用空间低于10%后,就不可以被insert ...

  10. unslider的用法详解

    unslider本身下载后只需要dist文件夹就好了, 其中只包含dist/js/unslider-min.js, jquery的js要自己提供; dist/css/unslider.css是主要的c ...