阅读 241

MasonryHidden

1.解决了什么问题

熟练使用masonry的童鞋,可以很快的使用masonry的属性搭建出复杂的UI页面.但是为了根据业务逻辑或者后台数据隐藏或者展示一个复杂页面的某一个或者某几个UI元素的时候,你可以会或多或少的会写一坨看起来不那么‘masonry’的语法.MasonryHidden优雅的解决了这个问题.

2.不使用MasonryHidden时

    //1.创建view
    UIView *subView1 = [[UIView alloc] init];
    [self.view addSubview:subView1];
    [subView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.right.equalTo(@(-20));
        make.top.equalTo(subView0.mas_bottom).offset(30);
        make.height.equalTo(@20);
    }];

    //2.根据业务逻辑或者数据进行隐藏或展示
    if (_subView1.hidden) {
        [_subView1 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@20);
            make.right.equalTo(@(-20));
            make.top.equalTo(_subView0.mas_bottom).offset(0);
            make.height.equalTo(@0);
        }];
    } else {
        [_subView1 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@20);
            make.right.equalTo(@(-20));
            make.top.equalTo(_subView0.mas_bottom).offset(30);
            make.height.equalTo(@20);
        }];
    }
复制代码

3.使用了MasonryHidden

    //1.创建view
    UIView *subView1 = [[UIView alloc] init];
    [self.view addSubview:subView1];
    [subView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.right.equalTo(@(-20));
        make.top.equalTo(subView0.mas_bottom).offset(30).autoHidden(subView1);
        make.height.equalTo(@20).autoHidden(subView1);
    }];

    //2.根据业务逻辑或者数据进行隐藏或展示
    _subView1.masonry_hidden = !_subView1.masonry_hidden;
复制代码

4.使用MasonryHidden

pod 'MasonryHidden'
复制代码

5.MasonryHidden源码地址

MasonryHidden