Browse Source

update examples

Jonas Budelmann 11 years ago
parent
commit
ece967ff53

+ 4 - 4
MasonryExamples/Masonry iOS Examples/MASExampleListViewController.m

@@ -35,18 +35,18 @@ static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
     self.exampleControllers = @[
         [[MASExampleViewController alloc] initWithTitle:@"Basic"
                                               viewClass:MASExampleBasicView.class],
+        [[MASExampleViewController alloc] initWithTitle:@"Update Constraints"
+                                              viewClass:MASExampleUpdateView.class],
         [[MASExampleViewController alloc] initWithTitle:@"Using Constants"
                                               viewClass:MASExampleConstantsView.class],
-        [[MASExampleViewController alloc] initWithTitle:@"Composite sides"
+        [[MASExampleViewController alloc] initWithTitle:@"Composite Edges"
                                               viewClass:MASExampleSidesView.class],
         [[MASExampleViewController alloc] initWithTitle:@"Basic Animated"
                                               viewClass:MASExampleAnimatedView.class],
-        [[MASExampleViewController alloc] initWithTitle:@"Debugging helpers"
+        [[MASExampleViewController alloc] initWithTitle:@"Debugging Helpers"
                                               viewClass:MASExampleDebuggingView.class],
         [[MASExampleViewController alloc] initWithTitle:@"Bacony Labels"
                                               viewClass:MASExampleLabelView.class],
-        [[MASExampleViewController alloc] initWithTitle:@"Update constraints"
-                                              viewClass:MASExampleUpdateView.class],
     ];
     
     return self;

+ 12 - 4
MasonryExamples/Masonry iOS Examples/MASExampleUpdateView.m

@@ -24,31 +24,39 @@
     self.growingButton = [UIButton buttonWithType:UIButtonTypeSystem];
     [self.growingButton setTitle:@"Grow Me!" forState:UIControlStateNormal];
     self.growingButton.layer.borderColor = UIColor.greenColor.CGColor;
-    self.growingButton.layer.borderWidth = 2;
+    self.growingButton.layer.borderWidth = 3;
 
     [self.growingButton addTarget:self action:@selector(didTapGrowButton:) forControlEvents:UIControlEventTouchUpInside];
     [self addSubview:self.growingButton];
 
     self.buttonSize = CGSizeMake(100, 100);
+
+    // make sure updateConstraints gets called
     [self setNeedsUpdateConstraints];
 
     return self;
 }
 
+// this is Apple's recommended place for adding/updating constraints
 - (void)updateConstraints {
     [super updateConstraints];
 
     [self.growingButton updateConstraints:^(MASConstraintMaker *make) {
         make.center.equalTo(self);
-        make.width.equalTo(@(self.buttonSize.width));
-        make.height.equalTo(@(self.buttonSize.height));
+        make.width.equalTo(@(self.buttonSize.width)).priorityLow();
+        make.height.equalTo(@(self.buttonSize.height)).priorityLow();
+        make.width.lessThanOrEqualTo(self);
+        make.height.lessThanOrEqualTo(self);
     }];
 }
 
 - (void)didTapGrowButton:(UIButton *)button {
-    self.buttonSize = CGSizeMake(self.buttonSize.width * 1.1, self.buttonSize.height * 1.1);
+    self.buttonSize = CGSizeMake(self.buttonSize.width * 1.3, self.buttonSize.height * 1.3);
 
+    // tell constraints they need updating
     [self setNeedsUpdateConstraints];
+
+    // update constraints now so we can animate the change
     [self updateConstraintsIfNeeded];
 
     [UIView animateWithDuration:0.4 animations:^{