masonry编写约束,默认的priority是1000

先看一个例子:

    [self.valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        UIView *superView = self.contentView;
        make.left.equalTo(self.titleLabel.mas_right).offset(24.0f);
        make.top.equalTo(self.titleLabel.mas_top);
        make.bottom.equalTo(self.titleLabel.mas_bottom);
        make.right.equalTo(superView.mas_right).offset(-padding);
    }];

在这个例子中,每个约束的priority的默认值是1000

然后,再看一个例子:

    [self.valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        UIView *superView = self.contentView;
        make.left.equalTo(self.titleLabel.mas_right).offset(24.0f);
        make.top.equalTo(self.titleLabel.mas_top);
        make.bottom.equalTo(self.titleLabel.mas_bottom);
        make.right.equalTo(superView.mas_right).offset(-padding).priorityHigh();
    }];

在这个例子中,右边距使用了priorityHigh(),看定义,hight的值是750

    typedef UILayoutPriority MASLayoutPriority;
    static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired;
    static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh;
    static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500;
    static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow;
    static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel;
static const UILayoutPriority UILayoutPriorityDefaultHigh NS_AVAILABLE_IOS(6_0) = 750; // This is the priority level with which a button resists compressing its content.

于是乎,写约束的时候,要注意下,不要以为priorityHight() 就是最高级别了,其实最高级别是 required(1000)。
优先级 在做一些微妙的调整时,可以起到四两拨千斤的效果;


生活不只是眼前的苟且,
还有...
...
...
...
...
...
远方的苟且

每个约束的priority的默认值是1000,我怎么知道?

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容