when I use masonry to layout my view i find that the behavior is quite diffrent between updateConstraints and 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);
}];
}
when i use updateConstraints
,the button will grow as expected,
but when i use remakeConstraints
,the button's frame remains "NSRect: {{127, 237}, {66, 30}}"
i wonder why?
Here is an explanation from an issue reported on the GitHub page for Masonry. https://github.com/SnapKit/Masonry/issues/81
mas_updateConstraints: is suitable for lightweight updates where you only need to change a constraint constant.
mas_remakeConstraints: method which uninstalls all constraints previously created for this view.
The complete uninstallation of all the constraints could be causing the difference in outcomes.