2016-06-14 50 views
0

,當我用磚石來佈置我的看法 我發現,行爲是updateConstraints和remakeConstraints磚石例如updateConstraints VS 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}}」

我想知道爲什麼?

+0

當我改變make.width.equalTo(@(self.buttonSize.width))。priorityLow(); make.height.equalTo(@(self.buttonSize.height))。priorityLow(); make.width.equalTo(@(self.buttonSize.width)); make.height.equalTo(@(self.buttonSize.height));有用 – user6434231

回答

1

下面是關於在砌體GitHub頁面上報告的問題的解釋。 https://github.com/SnapKit/Masonry/issues/81

mas_updateConstraints:適用於輕量級更新,您只需更改約束常量。

mas_remakeConstraints:卸載先前爲此視圖創建的所有約束的方法。

所有約束的完全卸載可能會導致結果的差異。