Authored by Jonas Budelmann

Update README.md

Showing 1 changed file with 24 additions and 0 deletions
@@ -204,6 +204,30 @@ make.center.equalTo(button1) @@ -204,6 +204,30 @@ make.center.equalTo(button1)
204 // make centerX = superview.centerX - 5, centerY = superview.centerY + 10 204 // make centerX = superview.centerX - 5, centerY = superview.centerY + 10
205 make.center.equalTo(superview).centerOffset(CGPointMake(-5, 10)) 205 make.center.equalTo(superview).centerOffset(CGPointMake(-5, 10))
206 ``` 206 ```
  207 +
  208 +## Hold on for dear life
  209 +
  210 +Sometimes you need to reference constraints so you can modify them at a later stage. This lets you animate or remove/replace constraints.
  211 +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.
  212 +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.
  213 +
  214 +```obj-c
  215 +// in public/private interface
  216 +@property (nonatomic, strong) id<MASConstraint> topConstraint;
  217 +
  218 +...
  219 +
  220 +// when making constraints
  221 +[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
  222 + self.topConstraint = make.top.equalTo(superview.mas_top).with.offset(padding.top);
  223 + make.left.equalTo(superview.mas_left).with.offset(padding.left);
  224 +}];
  225 +
  226 +...
  227 +// then later you can call
  228 +[self.topConstraint uninstall];
  229 +```
  230 +
207 ## When the ^&*!@ hits the fan! 231 ## When the ^&*!@ hits the fan!
208 232
209 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: 233 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: