, когда я использую кладку макет мой взгляд я считаю, что поведение вполне diffrent между updateConstraints и remakeConstraintsкладочные пример 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}}»
Интересно, почему?
когда я изменение make.width.equalTo (@ (self.buttonSize.width)). PriorityLow(); make.height.equalTo (@ (self.buttonSize.height)). PriorityLow(); to make.width.equalTo (@ (self.buttonSize.width)); make.height.equalTo (@ (self.buttonSize.height)); Оно работает – user6434231