美文网首页
Masonry约束立即生效跟约束更新

Masonry约束立即生效跟约束更新

作者: 搬码小能手 | 来源:发表于2019-10-30 14:57 被阅读0次
    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>>
    

    相关文章

      网友评论

          本文标题:Masonry约束立即生效跟约束更新

          本文链接:https://www.haomeiwen.com/subject/pqiovctx.html