1

当我使用砖石来布局我的视图时,我发现 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}}”

我想知道为什么?

4

1 回答 1

1

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

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

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

完全卸载所有约束可能会导致结果不同。

于 2016-08-12T17:24:03.270 回答