Reputation: 387
[self.line mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_line.superview).multipliedBy(0.5);
}];
[self.line mas_updateConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_line.superview).multipliedBy(1.66666);
}];
"<MASLayoutConstraint:0x14efa7170 UIView:0x14ef3f5a0.centerY == UIView:0x14ef3ec00.centerY * 0.5>",
"<MASLayoutConstraint:0x15026dcb0 UIView:0x14ef3f5a0.centerY == UIView:0x14ef3ec00.centerY * 1.66666>"
When I try to update the constraints, there will be a conflict, how to use it correctly?
It looks like the update operation has created a new constraint instead of changing its value.
Can't it be applied in mas_updateConstraints?
Do I have to use mas_remakeConstraints?
Upvotes: 1
Views: 819
Reputation: 1327
Apple doc says:
Unlike the other properties, the constant may be modified after constraint creation. Setting the constant on an existing constraint performs much better than removing the constraint and adding a new one that's just like the old but for having a new constant.
Let's paste some vanilla constraints below:
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:padding.top]
According to the doc, mas_updateConstraints
is supposed to change the constant value of an existing constraint, however, multiplier is not the constant part.
Use mas_remakeConstraints
instead, according to the doc, which remove all the existing ones before installing new ones.
Upvotes: 1