Authored by Jonas Budelmann

Update README.md

Showing 1 changed file with 27 additions and 2 deletions
... ... @@ -204,9 +204,12 @@ make.center.equalTo(superview).centerOffset(CGPointMake(-5, 10))
## Hold on for dear life
Sometimes you need to reference constraints so you can modify them at a later stage. This lets you animate or remove/replace constraints.
Sometimes you need modify existing constraints inorder to animate or remove/replace constraints.
In Masonry there are two common approaches for updating constraints.
#### 1. References
You can hold on to a reference of a particular constraint by assigning the result of a constraint make expression to a local variable or a class property.
You could also reference multiple constraints by storing them away in an array. You can see a demo of this in the animation example in **Masonry iOS Examples** project.
You could also reference multiple constraints by storing them away in an array.
```obj-c
// in public/private interface
... ... @@ -225,6 +228,28 @@ You could also reference multiple constraints by storing them away in an array.
[self.topConstraint uninstall];
```
#### 2. mas_updateConstraints
Alternatively if you are only updating the constant value of the constraint you can use the convience method `mas_updateConstraints` instead of `mas_makeConstraints`
```
// this is Apple's recommended place for adding/updating constraints
// this method can get called multiple times in response to setNeedsUpdateConstraints
// which can be called by UIKit internally or in your code if you need to trigger an update to your constraints
- (void)updateConstraints {
[super updateConstraints];
[self.growingButton mas_updateConstraints:^(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);
}];
}
```
You can find more detailed examples of both approaches in the **Masonry iOS Examples** project.
## When the ^&*!@ hits the fan!
Laying out your views doesn't always goto plan. So when things literally go pear shaped, you don't want to be looking at console output like this:
... ...