美文网首页iOS 开发
Masonry 单个约束的移除(卸载)和安装

Masonry 单个约束的移除(卸载)和安装

作者: tanpengsccd | 来源:发表于2017-08-25 14:38 被阅读2423次

Masonry小技巧门
来自 https://github.com/SnapKit/Masonry/issues/119
1 .属性中添加 约束

//
@property MASConstraint * expressWayViewHeight0;
@property MASConstraint * carWayViewViewHeight0;
//
  1. 开启约束,并存储约束
    [_expressWayView mas_updateConstraints:^(MASConstraintMaker *make) {
      _expressWayViewHeight0 =  make.height.mas_equalTo(0).priority(1000);
    }];
    [_carWayView mas_updateConstraints:^(MASConstraintMaker *make) {
      _carWayViewViewHeight0 =  make.height.mas_equalTo(0).priority(1000);
    }];

3 在需要的地方 移除(卸载)或者安装

if ([text.text isEqualToString:@"新增快递"] ||[text.text isEqualToString:@"原路返回"]) {
                            [_carWayViewViewHeight0 uninstall];
                            [_expressWayViewHeight0 install];
                        }else if ([text.text isEqualToString:@"自行派送"] ||[text.text isEqualToString:@"专车配送"]) {
                            [_carWayViewViewHeight0 install];
                            [_expressWayViewHeight0 uninstall];
                        }
 }

另外
mas_updateConstraints 也会产生 约束的数组
[MASViewConstraint installedConstraintsForView:yourView] 可以拿到所有约束数组

相关文章

网友评论

    本文标题:Masonry 单个约束的移除(卸载)和安装

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