view1 = [UIView new];
[self.view addSubview:view1];
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(10, 10, 10, 10));
}];
view1.backgroundColor = [UIColor redColor];
NSLog(@"%@",view1.description);
打印结果是:
<UIView: 0x7f9d20d0b650; frame = (0 0; 0 0); layer = <CALayer: 0x608000227900>>
在mas_makeConstraints之后用它的父视图调用layoutIfNeeded可以使得约束立即生效:
view1 = [UIView new];
[self.view addSubview:view1];
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(10, 10, 10, 10));
}];
view1.backgroundColor = [UIColor redColor];
[self.view layoutIfNeeded];
NSLog(@"%@",view1.description);
打印结果是:
<UIView: 0x7fa8d8d05730; frame = (10 10; 394 716); layer = <CALayer: 0x60800003ca20>>
网友评论