1)框架写法的四步优化
#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *blueView = [[UIView alloc]init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];
UIView *redView = [[UIView alloc]init];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.mas_equalTo(self.view.mas_top).multipliedBy(1).mas_offset(20);
// make.left.mas_equalTo(self.view.mas_left).multipliedBy(1).mas_offset(20);
//
// make.right.mas_equalTo(self.view.mas_right).multipliedBy(1).mas_offset(-20);
// make.bottom.mas_equalTo(self.view.mas_bottom).multipliedBy(1).mas_offset(-20);
// the first optmizi
// make.top.mas_equalTo(self.view.mas_top).mas_offset(20);
// make.left.mas_equalTo(self.view.mas_left).mas_offset(20);
// make.right.mas_equalTo(self.view.mas_right).mas_offset(-20);
// make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(-20);
//the second optmizi
make.top.mas_equalTo(self.view).mas_offset(20);
make.left.mas_equalTo(self.view).mas_offset(20);
make.right.mas_equalTo(self.view).mas_offset(-20);
make.bottom.mas_equalTo(self.view).mas_offset(-20);
//the third optmizi
// make.top.left.mas_equalTo(self.view).mas_equalTo(20);
// make.right.bottom.mas_equalTo(self.view).mas_offset(-20);
//the final optmizi
// make.edges.mas_offset(UIEdgeInsetsMake(20, 20, 20, 20));
}];
2)约束的更新和移除
#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *blueView = [[UIView alloc]init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];
//make
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsMake(20, 20, 20, 20));
}];
//replace
[blueView mas_updateConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsMake(50, 50, 50, 50));
}];
//remove
[blueView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsMake(100, 100, 100, 100));
}];
}
@end
#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *blueView = [[UIView alloc]init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];
UIView *redView = [[UIView alloc]init];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.mas_equalTo(self.view).mas_offset(20);
make.right.mas_equalTo(self.view).mas_offset(-20);
make.height.mas_offset(100);
}];
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(blueView.mas_bottom).mas_offset(50);
make.trailing.mas_equalTo(blueView);
make.height.mas_equalTo(blueView);
make.width.mas_equalTo(blueView).multipliedBy(0.5);
}];
}
@end
2784

被折叠的 条评论
为什么被折叠?



