gpt4 book ai didi

ios - 砌体示例 updateConstraints 与 remakeConstraints

转载 作者:行者123 更新时间:2023-12-01 22:29:35 25 4
gpt4 key购买 nike

当我使用砖石来布置我的视野时
我发现 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com