ios - 砌体示例 updateConstraints 与 remakeConstraints

标签 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}}”

我想知道为什么?

最佳答案

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

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

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

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

关于ios - 砌体示例 updateConstraints 与 remakeConstraints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37810178/

相关文章:

ios - MIDIDestinationCreate 和 UIBackgroundmodes

ios - Objective C Table Cell ContentView view hierarchy is not prepared for the constraint

ios - 我什么时候应该在区 block 中使用弱势 self ,为什么砌体中没有保留周期?

ios - 将砌体 x/y 约束设置为 View 宽度/高度的百分比

ios - 我应该为 CFBundleVersion 和 CFBundleShortVersionString 使用什么值?

ios - 在 Swift 中使用 Objective-C 类时出现 "Cannot Find Initializer"

ios - 如何使用 Dropbox Sync API 使目录及其内容保持同步?

objective-c - 如何处理openGL中几个圆圈的淡出?

iPhone 应用程序在访问 NSString 时随机退出