美文网首页iOS开发新发现
Masonry的优先级,更新,重置

Masonry的优先级,更新,重置

作者: dicesc | 来源:发表于2016-07-08 21:44 被阅读3605次

    //实例化一个view

    UIView*redView = [UIViewnew];

    redView.backgroundColor= [UIColorredColor];

    [self.viewaddSubview:redView];

    UIView*blueView = [UIViewnew];

    blueView.backgroundColor= [UIColorblueColor];

    [self.viewaddSubview:blueView];

    //masonry自动帮我们把autoresizing给禁用掉


    /**

    更新约束

    updateConstraints:

    更新redView的约束高度变为80

    [redView updateConstraints:^(MASConstraintMaker *make) {

    make.height.equalTo(80);

    }];

    */


    /**

    重新设置,会把之前的约束给清空掉,然后使用新的约束

    remakeConstraints :

    [redView remakeConstraints:^(MASConstraintMaker *make) {

    make.top.left.offset(20);

    make.right.offset(-20);

    make.height.equalTo(80);

    }];

    */


    /**

    设置约束的优先级

    .priority(10)

    [redView makeConstraints:^(MASConstraintMaker *make) {

    make.top.left.offset(20);

    make.right.offset(-20);

    //make.height.equalTo(40).priorityLow();

    make.height.equalTo(40).priority(10);

    }];

    [redView makeConstraints:^(MASConstraintMaker *make) {

    make.height.equalTo(80).priority(20);

    }];

    */


    [redViewmakeConstraints:^(MASConstraintMaker*make) {

    //make.top.left.offset(20);

    //针对topLayoutGuide进行设置

    // self.mas_bottomLayoutGuide设置底部

    // self.mas_topLayoutGuideBottom设置顶部

    make.top.equalTo(self.mas_topLayoutGuideBottom);

    make.left.offset(20);

    make.right.offset(-20);

    make.height.equalTo(40);

    }];

    //设置blueView的约束

    /**

    dividedBy :除以

    multipliedBy :乘以

    */

    [blueViewmakeConstraints:^(MASConstraintMaker*make) {

    make.top.equalTo(redView.bottom).offset(20);

    make.right.offset(-20);

    make.height.equalTo(redView);

    //宽度

    //make.width.equalTo(redView).multipliedBy(0.5);

    make.width.equalTo(redView).dividedBy(2);

    }];

    //更新

    [redViewupdateConstraints:^(MASConstraintMaker*make) {

    make.height.equalTo(80);

    }];

    相关文章

      网友评论

      • 萝卜酱紫:更新约束需要,改变的是 之前相同的约束(补充下)。设置优先级让高优先级的失效呢

      本文标题:Masonry的优先级,更新,重置

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