#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)
**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.greaterThanOrEqualTo(label.mas_left).with.priorityLow();
make.top.equalTo(label.mas_to
没有合适的资源?快使用搜索试试~ 我知道了~
UICollectionView横向滑动的两种效果。
共628个文件
h:183个
m:99个
json:8个
4星 · 超过85%的资源 需积分: 49 157 下载量 172 浏览量
2016-07-22
17:33:20
上传
评论 2
收藏 4.67MB ZIP 举报
温馨提示
UICollectionView横向滑动的两种效果 1. 减速效果 2.分页效果 Demo详解地址:http://blog.csdn.net/yutianlong9306/article/details/51994314
资源推荐
资源详情
资源评论
收起资源包目录
UICollectionView横向滑动的两种效果。 (628个子文件)
0069199c5d0652fb86b9d2c5c7a802357a6dad 286B
00cc21855ef119770f7d50ddbf01fe9f273f85 223B
00dd8cb87cc037bc61414014f288eae59a8e43 366B
025daccb58e98be8d3008f1a8f27670081059c 302B
039b3994ac8c4568564644e829bf0d8dff8c11 2KB
05cc67bbf738499f2accb4b56f5f1ddc8ce444 506B
05ccefcca558e9227095bcdbf9c0e1dd4f14d1 220B
065faf8b0785a29c6e8e58e4d0e4545bfccb42 235B
075bf5c3bf9801fc8e3ca53a055311a56ddcd8 1KB
07d216be6832019fe9d7790bccfaab2f31f4f2 755B
08bde4b52b3afb237dcaa126e5606006fb6980 4KB
09d8304a5b5b1f1cf65bb7a1513e7ee24d784d 1KB
0b601bcf6c2d74a0c0adf206ae99932e1a9294 414B
0d6fd859a94b57739040ddf4aa8a995fb9535c 10KB
0d8944c6b72aba76cd988140abd151b706afe4 269B
0e036ee49c087ad079b6f3af37a7d0f39d93d5 1KB
0f41c53dce342fbff3c72b4e3aef50e4b6b73d 1KB
0fa44591bbab0d370f1344d80d20ef510e9458 4KB
0fd960827d384dbc1f979e4ee10ad76ce30231 811B
109f024ad4d05f2c47fe25d3d5f745c8ee404b 273B
10f1b6816f3394843a6e50b0cd4d563fef0480 2KB
127f25ba6c303a83381f4e6ab024fdd1e6f646 196B
129e139e7ccde4ddaafa19ee35294314a81181 111B
12ae3b3049edfb8604cdfd18f448a777df6dd3 64B
12e6eb9ce1ecb1a0f4d7c287ffa381da0f8e3b 224B
14515e6745d1949ce273cfc88f54efabedeb81 187B
146c47f1e8394524d6b2225cbb5f365fa4dbd7 281B
14b9c629c89f140e4b7249d8036de66838e80d 3KB
14c3522aa07506b5d4ae16ada2ac7202933baa 1022B
156705539e065367057404df75dd34b4ab061b 230B
16b6cb1d01feb20a4a64cdc6f2579d9837232c 180B
16d581a76dc93a05402c9dd9824b12ca75f6bd 90KB
1953b9f9f16239c8c3c7ef3cc9cea2553d34b4 7KB
1a078c0a34cc00c0ea4b9c16ee69bb5ff5c684 1KB
1a2d8d70282b8c1e87b91dcd4ea36b90d22aa3 156B
1a3635089b42e4c15b44a3739d1c95c70bcc33 150B
1a85924a26b48cae938fb0b726b3441bd8194d 885B
1b1eb6f790103b8ac699440d7e2873ae573e7a 708B
1b4731002e0fdbfc1c73939730a32358c3baac 152B
1b63de1b4f3f1028bd141f614f73dc545c5b07 2KB
1cdd9b6b8f76b97291c4f318a84d4354cd3a6d 642B
1e00986ca54611ec502323ea48f12a2ea4437a 1KB
1e28eb02a16d4b9de07b30397dd7cdfc50aa90 1KB
1e8ae7bebd7dacd24045facae28bb4da38cc8b 1KB
1ee0635271a7d2346aaf038a9d028a47c4aa79 181B
1f1289fc70d5bb5b3410c791433b25a299aa61 1KB
1f1c1bc8574cfefa40bab305f051672a02b35e 144B
1fe091b5a556fa5d5e1d929f3e9a0484a2c40d 600B
1ff1d8a13294302ca91362e736afd1b9e0832c 181B
2056c7a23e7973fe1304d123a4a377e7ec8718 352B
21600758e50d753602c210f3192211f4c0ead1 1KB
217e855c04423c8ede62f6f3091443e9b65f8c 223KB
234d5e56b7014599fd392e02fe82bcbf6b3158 290B
23a5c80f3ef7881e1eace1808b318b532a0268 1KB
2827a11c40291b629c684a695016220f6090bf 337B
29181bbef817c77838007704409f6bc7365f51 598B
297e0bb414254ba340ca297a33488199b1bd3d 244B
2a8cbf5b4fdc611aaa74ed131500c927946e1e 377B
309dbb013f22fd27aff790ff41dbe900cc5292 752B
30e4384efd4df586b5af643709ae36e46649be 51B
31025d7ff3336a0f7db2a6e33a518d55317c3b 504B
3639df1d8ef5940cc4ea8f5708badaa8c730f5 175B
37989332f8025768290a617573879256ae4987 2KB
3a6d69bc1e151b82f22b4ac7671347aa1bf0e2 5KB
3abb6211aeeda29cba4b25cd79c478a7de0a41 251B
3ae65de66fe73e860ab65d146a847c6dda781d 541B
3b68d62d60b48a9a5890b5243345cf19abe8df 1KB
3b6f946d43205e100266b05c6787c173326f07 175B
3b73acdf4081254d6e3d39f44b2b5aac82550b 348B
3b76fa74b0842c7d21983977a7125deb7bcc64 1KB
3bd7b365ba4e6a4b9b45ee24966d354cfce390 175B
3c4f064d34751e4cd49440299c2e746a7d6dbc 519B
3ca5c90b7f89a87dee9ee5355e8acc6aaf9681 158B
40a264428fe2a578b305b79befc00d05f8aed6 2KB
41b7b11291b1dedf45598d2f42aeb84e5fbdb9 424B
42c8e282ad56d28101b9389a7352096ddac2b3 264B
43870398b8e85f1eb4e32cddba896fc01b0bc7 180B
43c00c260d8ce378dec6b57fd0e766233ce646 665B
43c630fcc3ffcb43cba5e3442b65c607026b44 284B
4602642ea0a600ea9e26f08644e60c74a2d53a 144B
460569efce5424fa975938dd32e92fea6c211b 866B
4736977e3ae5c1124a00552f81c7d5815df4de 383B
47788d19dd2880224f6bfa8746ddca082adbe3 132B
49e8831379cef240b601d4391f93911fd35087 287B
4a164c918651cdd1e11dca5cc62c333f097601 65B
4c6f166e0d1f85a3fe72e14c81a1f0767f46cf 298B
4d24e30bf5426ce98f2b40b6fdfe02dfc7f13d 103KB
4d2ea4c5a67084b0ee0aa21cc2b92db5bf0e8a 200B
4ea0b67d12d46bcdf64e101cd7ee7cfa9687cf 126B
4ea6136781ac4ac7a0887dcd3e6969f55c0d88 180B
4ec1041274f1306ce0d1be509facc16ee2afe3 2KB
4edbdf26c2135d41f937e2c6039bab9a56999a 332B
4f7f8e33359a1f5ed881f5422d59906eeac42b 1KB
4fdce4f65572011a2fcf4fa4b7394093702631 145B
4fe39edccf7c6f6466562c2e10e5e4796f6438 840B
5138e76e493ba8c3362ce8bb015f42a7c1fc3c 3KB
5139fac520a13bec9f705f132ca512f5fc1117 337B
5184e00ff6890af2293df3bd79e094b3668b06 858B
5191ecb53498e14f0b434330d7a08bcb1865db 149B
51a0a8ae478929144f4415d9e8d18bf571ee49 2KB
共 628 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
TimoreYu
- 粉丝: 18
- 资源: 36
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页