一. 继承关系

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. webservice理解

    什么是webservice? 1.基于web的一种服务,webservice分为服务器端server和客户端client. server端会会提供一些资源供客户端的应用来访问(获取所需要的数据) 2. ...

  2. sql 列转行 实例

    select * from dbo.orders  group by  custid  with cube    select custid ,row_number() over(order by e ...

  3. Java包装类

    自动装箱:指开发人员可以把一个基本数据类型直接赋给对应的包装类 自动拆箱:指开发人员可以把一个包装类对象直接赋给对应的基本数据类型 要把基本数据类型称为对象的时候,需要把基本数据类型进行包装, 运用: ...

  4. Envelope Letter

    http://www.thefullwiki.org/More_C%2B%2B_Idioms/Envelope_Letter http://www.smallmemory.com/almanac/Co ...

  5. Object.prototype.toString.call() 区分对象类型

    判断一个对象的类型: /** * 判断对象是否为数组 * @param {Object} source 待判断的对象 * @return {Boolean} true|false */ Object. ...

  6. xhprof安装使用

    安装: 到pecl官网下载xhprof的最新版:http://pecl.php.net/package/xhprof wget http://pecl.php.net/get/xhprof-0.9.4 ...

  7. [Unity] 精灵动画制作中需要注意的一些问题

    1. 为精灵添加了动画控制器,UpdateMode设置为了Animate Physics,精灵就不受控制了,在游戏中不断的晃动,不受重力影响向下掉等奇葩问题出现了. 解决办法: 此类问题,除掉刚体设置 ...

  8. 微信小程序 教程及示例

    作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有,转载请联系作者获得授权.微信小程序正式公测, ...

  9. 获取实体属性名称(Property)和DisplayName属性名称(Attribute)

    代码: public Dictionary<string, string> XXXModelColumnName { get { var dic = new Dictionary<s ...

  10. IOS开发中@2x图片等适应不同分辨率手机

    开发中,例如: nanshanImage.image=[UIImage imageNamed:@'index_pic.png']; 在项目中还保存中index_pic@2x.png的图片,此图为了只适 ...