砌体示例updateConstraints vs remakeConstraints

时间:2016-06-14 11:03:18

标签: ios objective-c masonry-ios-osx

当我使用砌体布置我的视图时 我发现updateConstraints和remakeConstraints

之间的行为非常不同
- (id)init {
self.growingButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.growingButton setTitle:@"Grow Me!" forState:UIControlStateNormal];
self.growingButton.layer.borderColor = UIColor.greenColor.CGColor;
self.growingButton.layer.borderWidth = 3;

[self.growingButton addTarget:self action:@selector(didTapGrowButton:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.growingButton];

self.buttonSize = CGSizeMake(100, 100);

[self.growingButton makeConstraints:^(MASConstraintMaker *make) {
    make.center.equalTo(self);
    make.width.equalTo(@(self.buttonSize.width)).priorityLow();
    make.height.equalTo(@(self.buttonSize.height)).priorityLow();
    make.width.lessThanOrEqualTo(self);
    make.height.lessThanOrEqualTo(self);
}];
...
return self;
}
//click button 
- (void)didTapGrowButton:(UIButton *)button {

self.buttonSize = CGSizeMake(self.buttonSize.width * 1.3, self.buttonSize.height * 1.3);
NSLog(@"===============================");
[self.growingButton updateConstraints:^(MASConstraintMaker *make) {
//    [self.growingButton remakeConstraints:^(MASConstraintMaker *make) {
    make.center.equalTo(self);
    make.width.equalTo(@(self.buttonSize.width)).priorityLow();
    make.height.equalTo(@(self.buttonSize.height)).priorityLow();
    make.width.lessThanOrEqualTo(self);
    make.height.lessThanOrEqualTo(self);
}];
}

当我使用updateConstraints时,按钮会按预期增长, 但是当我使用remakeConstraints时,按钮的框架仍为" NSRect:{{127,237},{66,30}}"

我想知道为什么?

1 个答案:

答案 0 :(得分:1)

以下是针对Masonry的GitHub页面上报告的问题的解释。 https://github.com/SnapKit/Masonry/issues/81

mas_updateConstraints:适用于只需要更改约束常量的轻量级更新。

mas_remakeConstraints:卸载先前为此视图创建的所有约束的方法。

完全卸载所有约束可能会导致结果的差异。