iOS开发新发现

Masonry的优先级,更新,重置

2016-07-08  本文已影响3605人  dicesc

//实例化一个view

UIView*redView = [UIViewnew];

redView.backgroundColor= [UIColorredColor];

[self.viewaddSubview:redView];

UIView*blueView = [UIViewnew];

blueView.backgroundColor= [UIColorblueColor];

[self.viewaddSubview:blueView];

//masonry自动帮我们把autoresizing给禁用掉


/**

更新约束

updateConstraints:

更新redView的约束高度变为80

[redView updateConstraints:^(MASConstraintMaker *make) {

make.height.equalTo(80);

}];

*/


/**

重新设置,会把之前的约束给清空掉,然后使用新的约束

remakeConstraints :

[redView remakeConstraints:^(MASConstraintMaker *make) {

make.top.left.offset(20);

make.right.offset(-20);

make.height.equalTo(80);

}];

*/


/**

设置约束的优先级

.priority(10)

[redView makeConstraints:^(MASConstraintMaker *make) {

make.top.left.offset(20);

make.right.offset(-20);

//make.height.equalTo(40).priorityLow();

make.height.equalTo(40).priority(10);

}];

[redView makeConstraints:^(MASConstraintMaker *make) {

make.height.equalTo(80).priority(20);

}];

*/


[redViewmakeConstraints:^(MASConstraintMaker*make) {

//make.top.left.offset(20);

//针对topLayoutGuide进行设置

// self.mas_bottomLayoutGuide设置底部

// self.mas_topLayoutGuideBottom设置顶部

make.top.equalTo(self.mas_topLayoutGuideBottom);

make.left.offset(20);

make.right.offset(-20);

make.height.equalTo(40);

}];

//设置blueView的约束

/**

dividedBy :除以

multipliedBy :乘以

*/

[blueViewmakeConstraints:^(MASConstraintMaker*make) {

make.top.equalTo(redView.bottom).offset(20);

make.right.offset(-20);

make.height.equalTo(redView);

//宽度

//make.width.equalTo(redView).multipliedBy(0.5);

make.width.equalTo(redView).dividedBy(2);

}];

//更新

[redViewupdateConstraints:^(MASConstraintMaker*make) {

make.height.equalTo(80);

}];

上一篇下一篇

猜你喜欢

热点阅读