#Masonry [![Build Status](https://travis-ci.org/SnapKit/Masonry.svg?branch=master)](https://travis-ci.org/SnapKit/Masonry) [![Coverage Status](https://img.shields.io/coveralls/SnapKit/Masonry.svg?style=flat-square)](https://coveralls.io/r/SnapKit/Masonry) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Pod Version](https://img.shields.io/cocoapods/v/Masonry.svg?style=flat)
**Masonry is still actively maintained, we are committed to fixing bugs and merging good quality PRs from the wider community. However if you're using Swift in your project, we recommend using [SnapKit](https://github.com/SnapKit/SnapKit) as it provides better type safety with a simpler API.**
Masonry is a light-weight layout framework which wraps AutoLayout with a nicer syntax. Masonry has its own layout DSL which provides a chainable way of describing your NSLayoutConstraints which results in layout code that is more concise and readable.
Masonry supports iOS and Mac OS X.
For examples take a look at the **Masonry iOS Examples** project in the Masonry workspace. You will need to run `pod install` after downloading.
## What's wrong with NSLayoutConstraints?
Under the hood Auto Layout is a powerful and flexible way of organising and laying out your views. However creating constraints from code is verbose and not very descriptive.
Imagine a simple example in which you want to have a view fill its superview but inset by 10 pixels on every side
```obj-c
UIView *superview = self.view;
UIView *view1 = [[UIView alloc] init];
view1.translatesAutoresizingMaskIntoConstraints = NO;
view1.backgroundColor = [UIColor greenColor];
[superview addSubview:view1];
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
[superview addConstraints:@[
//view1 constraints
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:padding.top],
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:padding.left],
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:-padding.bottom],
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeRight
multiplier:1
constant:-padding.right],
]];
```
Even with such a simple example the code needed is quite verbose and quickly becomes unreadable when you have more than 2 or 3 views.
Another option is to use Visual Format Language (VFL), which is a bit less long winded.
However the ASCII type syntax has its own pitfalls and its also a bit harder to animate as `NSLayoutConstraint constraintsWithVisualFormat:` returns an array.
## Prepare to meet your Maker!
Heres the same constraints created using MASConstraintMaker
```obj-c
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(superview.mas_top).with.offset(padding.top); //with is an optional semantic filler
make.left.equalTo(superview.mas_left).with.offset(padding.left);
make.bottom.equalTo(superview.mas_bottom).with.offset(-padding.bottom);
make.right.equalTo(superview.mas_right).with.offset(-padding.right);
}];
```
Or even shorter
```obj-c
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(superview).with.insets(padding);
}];
```
Also note in the first example we had to add the constraints to the superview `[superview addConstraints:...`.
Masonry however will automagically add constraints to the appropriate view.
Masonry will also call `view1.translatesAutoresizingMaskIntoConstraints = NO;` for you.
## Not all things are created equal
> `.equalTo` equivalent to **NSLayoutRelationEqual**
> `.lessThanOrEqualTo` equivalent to **NSLayoutRelationLessThanOrEqual**
> `.greaterThanOrEqualTo` equivalent to **NSLayoutRelationGreaterThanOrEqual**
These three equality constraints accept one argument which can be any of the following:
#### 1. MASViewAttribute
```obj-c
make.centerX.lessThanOrEqualTo(view2.mas_left);
```
MASViewAttribute | NSLayoutAttribute
------------------------- | --------------------------
view.mas_left | NSLayoutAttributeLeft
view.mas_right | NSLayoutAttributeRight
view.mas_top | NSLayoutAttributeTop
view.mas_bottom | NSLayoutAttributeBottom
view.mas_leading | NSLayoutAttributeLeading
view.mas_trailing | NSLayoutAttributeTrailing
view.mas_width | NSLayoutAttributeWidth
view.mas_height | NSLayoutAttributeHeight
view.mas_centerX | NSLayoutAttributeCenterX
view.mas_centerY | NSLayoutAttributeCenterY
view.mas_baseline | NSLayoutAttributeBaseline
#### 2. UIView/NSView
if you want view.left to be greater than or equal to label.left :
```obj-c
//these two constraints are exactly the same
make.left.greaterThanOrEqualTo(label);
make.left.greaterThanOrEqualTo(label.mas_left);
```
#### 3. NSNumber
Auto Layout allows width and height to be set to constant values.
if you want to set view to have a minimum and maximum width you could pass a number to the equality blocks:
```obj-c
//width >= 200 && width <= 400
make.width.greaterThanOrEqualTo(@200);
make.width.lessThanOrEqualTo(@400)
```
However Auto Layout does not allow alignment attributes such as left, right, centerY etc to be set to constant values.
So if you pass a NSNumber for these attributes Masonry will turn these into constraints relative to the view’s superview ie:
```obj-c
//creates view.left = view.superview.left + 10
make.left.lessThanOrEqualTo(@10)
```
Instead of using NSNumber, you can use primitives and structs to build your constraints, like so:
```obj-c
make.top.mas_equalTo(42);
make.height.mas_equalTo(20);
make.size.mas_equalTo(CGSizeMake(50, 100));
make.edges.mas_equalTo(UIEdgeInsetsMake(10, 0, 10, 0));
make.left.mas_equalTo(view).mas_offset(UIEdgeInsetsMake(10, 0, 10, 0));
```
By default, macros which support [autoboxing](https://en.wikipedia.org/wiki/Autoboxing#Autoboxing) are prefixed with `mas_`. Unprefixed versions are available by defining `MAS_SHORTHAND_GLOBALS` before importing Masonry.
#### 4. NSArray
An array of a mixture of any of the previous types
```obj-c
make.height.equalTo(@[view1.mas_height, view2.mas_height]);
make.height.equalTo(@[view1, view2]);
make.left.equalTo(@[view1, @100, view3.right]);
````
## Learn to prioritize
> `.priority` allows you to specify an exact priority
> `.priorityHigh` equivalent to **UILayoutPriorityDefaultHigh**
> `.priorityMedium` is half way between high and low
> `.priorityLow` equivalent to **UILayoutPriorityDefaultLow**
Priorities are can be tacked on to the end of a constraint chain like so:
```obj-c
make.left.greaterThanOr
没有合适的资源?快使用搜索试试~ 我知道了~
iOS单个控制器横屏2
共174个文件
h:23个
m:21个
png:10个
3星 · 超过75%的资源 需积分: 50 69 下载量 101 浏览量
2017-11-02
11:22:27
上传
评论
收藏 632KB ZIP 举报
温馨提示
1.实现全局支持竖屏,某个控制器页面允许横竖屏切换的功能2.是从ijk播放器项目中抽出的界面,利用masonry适配3.因为ijk库过大,该项目未上传,暂不支持视频播放
资源推荐
资源详情
资源评论
收起资源包目录
iOS单个控制器横屏2 (174个子文件)
01f262c1a46b28269252017e5e73152605a1b1 52B
05cde7918b955beb8e6c2b5ecad1f27e9180d5 467B
0e44f46d823c4c052eaf784aa0c612c7e6ce77 190B
1059fc4a224cc5fa48d63ed117264baba26489 192B
1209af8a158013e90073fd19a93bfb450e7dd6 181B
22b1dd08a78b57d3720fb04ad66c35d4505e62 527B
23339828ab03b25311b69b2125fbe08d7ba0d6 152B
236c65348164bf01a6f5e909f07ea57ade94ce 171B
258f2dca7077060277032ac338456ff7837cc9 1KB
29698c4c56ae1c65c132f2754a23d888259a74 781B
37842cee02797dc769a32b56e2ab2c4d2bca3b 4KB
3836f73034274af1ce94ce44dad696cbe7e8d1 326B
40f10a04ce7e0ef3208a18bd3120e13c8d2cdb 130B
43a3f1230d8ede892e205fc7c3b73b512269ec 173B
4821ed2e7529187ff99c40ecb98a5744a58b27 198KB
4930b3b35d34d32cd1a61d3460e5219207dc1a 270B
4a164c918651cdd1e11dca5cc62c333f097601 65B
4c8bdcc6c0fd59205e98b4fb802a5ac6d1c93c 4KB
517bbfe7e54935dc378dde6c126536341d7810 3KB
53ee99d4de30d31c087344bd59c18f25b1e41d 172B
65464310c587b43a1afe34b3f1925aa36018bf 170B
66afcd5596fdc415e29ab0bc6c882f1425b87e 324B
6758e0c123e69035fc887e8bf11fe1856069f6 69B
6c23c43adc88621ce3abfbd1585c8792bd165c 339B
73c1db90544d64ba8220826f40f07f0b2a47e1 156B
75bfbe8fb794d18dc518e04b8ca38b5b851f42 139B
7cc785c783d1474781f28b2bde7a41cff0803b 1KB
809ea5cf4dbfa9e3a8bdccaf925f6cdcf8814c 232B
829be307594cc379274d714196eb37606eb2c7 644B
871aff5ddbf8f4fd7c73f73af65ce40c145776 923B
8b9725270259354716b5d75be36df9a613abae 178B
8bec368f70142ee9332dd35d8021ac3e262650 60B
8c98f7461bf98b2bc7e061150d8021121ad277 161B
98bcf74d25092218af3941acff5b107b529c9a 1KB
9d221ed49ce1df662bbf4cf575cbd6a59f7fd2 1KB
9d35069e16c3a595edd0373ae9bb1517744302 492B
a5e8d4b98b975bbc63aef49f363a8e9cb73d6e 109B
b4ed18fbe955433f9d3e9692499657972d94ef 97B
b616f0e8f4487791d50e620e6df67037c621da 57B
bf7f42b7757b3076a7d2f5afc476488f6613e0 59B
c2ac124b8f7ddbdc318cdec5103e216e8da5fa 2KB
c4eb63d10c74fde83321d3325e53f7141ff182 173B
ca109dec4109bfb9a1751e7169095809594b7e 3KB
cc002b382696c08bf9060c8245134c9e6f26c2 171B
COMMIT_EDITMSG 15B
config 137B
description 73B
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
e5528e8c050237bbd15f652ffba3a27413207d 4KB
e5ed3867c7d32e3a9b5b6793898077214381cf 136B
e63fc9ec2b45557e8fa2f2d5c4f85b16feab8d 491B
e98af23d391ddd93a0c47f4113cb2fb64606d5 494B
eab2ce39ace669e38967b0b7baec33f18b59eb 94B
exclude 40B
f22bc2ab393bbcbb4400415995d9bfec01bc90 98B
f374c80d22d661ff254e8becfa3dc6dabb9bf0 286B
f3f97d1b6e9d8d29bb69a88c4d89ca752bd937 807B
fa225a0cc1bf43ed96be00f1485935b7681430 287B
fb934e2a021b09c1b883a9ca43cfdab5aac7d3 146B
MBProgressHUD.h 16KB
MASConstraint.h 7KB
MASUtilities.h 6KB
MASConstraintMaker.h 5KB
View+MASAdditions.h 4KB
View+MASShorthandAdditions.h 4KB
NSArray+MASAdditions.h 3KB
MASConstraint+Private.h 2KB
MASViewConstraint.h 1KB
MASViewAttribute.h 1KB
NSArray+MASShorthandAdditions.h 1016B
ViewController+MASAdditions.h 891B
Masonry.h 802B
Masonry-umbrella.h 801B
HSPlayerView.h 643B
MASLayoutConstraint.h 505B
MASCompositeConstraint.h 494B
AppDelegate.h 362B
MBProgressHUD-umbrella.h 344B
Pods-HSIJKTestDemo-umbrella.h 328B
NSLayoutConstraint+MASDebugAdditions.h 326B
HSBaseNavgationController.h 242B
HSPlayMainViewController.h 234B
HEAD 159B
HEAD 23B
index 5KB
Contents.json 753B
Contents.json 380B
Contents.json 376B
Contents.json 374B
Contents.json 372B
Contents.json 309B
Contents.json 304B
Contents.json 62B
LICENSE 1KB
共 174 条
- 1
- 2
资源评论
- 蘑菇小菜2018-07-02嗯呢, 很熟不粗的
hahamuyu
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功