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

2016-10-14  本文已影响3150人  zhangyin

先看一个例子:

    [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,我怎么知道?

上一篇 下一篇

猜你喜欢

热点阅读