分析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;
};
}
分析Masonry的更多相关文章
- iOS开发之Masonry框架源码深度解析
Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...
- Masonry框架源码深度解析
Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...
- iOS开发之Masonry框架源码解析
Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
打个小广告:本人开发了一个宠物相关的App,欢迎大家下载体验~ 下载二维码: 进入正文: 之前发过一篇博客,也是对这两个的练习使用,但是之后遇到些问题,所以删除重写了.抱歉 Masonry是一款轻量级 ...
- 【原】Masonry+UIScrollView的使用注意事项
[原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...
- 【转】有趣的Autolayout示例-Masonry实现
原文网址:http://tutuge.me/2015/05/23/autolayout-example-with-masonry/ 好久没有写Blog了,这段时间有点忙啊=.=本文举了3个比较有“特点 ...
- iOS开发 masonry 设置tableHeadView
最近做公司项目,使用到到tableHeadView,一直习惯用masonry来设置约束,但是设置tableHeadView没有那么的简单.先看下效果图: 视图层次结构是这样的: 基础的创建工程项目之类 ...
- 【HELLO WAKA】WAKA iOS客户端 之一 APP分析篇
由于后续篇幅比较大,所以调整了内容结构. 全系列 [HELLO WAKA]WAKA iOS客户端 之一 APP分析篇 [HELLO WAKA]WAKA iOS客户端 之二 架构设计与实现篇 [HELL ...
- IOS控件布局之Masonry布局框架
前言: 回想起2013年做iOS开发的时候,那时候并没有采用手写布局代码的方式,而是采用xib文件来编写,如果使用纯代码方式是基于window的size(320,480)计算出一个相对位置进行布局,那 ...
随机推荐
- 淘淘商城maven工程的创建和svn的上传实现
后台管理系统工程结构 maven管理的好处 1.项目构建.Maven定义了软件开发的整套流程体系,并进行了封装,开发人员只需要指定项目的构建流程,无需针对每个流程编写自己的构建脚本. 2.依赖管理.除 ...
- jQuery小技巧
1. 禁止右键点击 $(document).bind("contextmenu",function(e){ return false; }); 2.隐藏搜索文本框文字 $(docu ...
- 整数分解 && 质因数分解
输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...
- dos命令复制当天生成的以日期为文件名的文件
1.利用SqlServer的自动备份功能,将数据自动备份,备份出的文件格式如下: db_backup_201001270930.bak 2.编辑bat脚本 ...
- Java——复选框:JCheckBox
import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ItemEvent; import java. ...
- C#----使用WindowsMediaPlayer 同时播放多个声音
使用Windows Media Player 其实就是使用组件AxWindowsMediaPlayer. 添加两个引用:Interop.WMPLib.dll和AxInterop.WMPLib.dll. ...
- 如何在Flash Builder里新建ActionScript工程
新建ActionScript工程 1. File > New > ActionScript Project 2. 按照提示完成工程的创建 使程序直接在Flash Player中运行 1. ...
- [webgrid] – header - (How to Add custom html to Header in WebGrid)
How to Add custom html to Header in WebGrid MyEvernote Link Posted on March 30, 2013by mtryambake Ho ...
- IIS站点无法访问..点浏览IIS窗口直接关掉
呃..其实这个问题很简单.. 大家可以先看这位大婶写的博文.. http://blog.csdn.net/chenguang79/article/details/7220232 如果网站一访问IIS就 ...
- 负margin小记
static元素 margin-top/left负值,元素向指定方向移动, margin-bottom/right负值,元素不动,后续元素前移 float元素 左浮, ...