MASExampleUpdateView.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // MASExampleUpdateView.m
  3. // Masonry iOS Examples
  4. //
  5. // Created by Jonas Budelmann on 3/11/13.
  6. // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7. //
  8. #import "MASExampleUpdateView.h"
  9. @interface MASExampleUpdateView ()
  10. @property (nonatomic, strong) UIButton *growingButton;
  11. @property (nonatomic, assign) CGSize buttonSize;
  12. @end
  13. @implementation MASExampleUpdateView
  14. - (id)init {
  15. self = [super init];
  16. if (!self) return nil;
  17. self.growingButton = [UIButton buttonWithType:UIButtonTypeSystem];
  18. [self.growingButton setTitle:@"Grow Me!" forState:UIControlStateNormal];
  19. self.growingButton.layer.borderColor = UIColor.greenColor.CGColor;
  20. self.growingButton.layer.borderWidth = 2;
  21. [self.growingButton addTarget:self action:@selector(didTapGrowButton:) forControlEvents:UIControlEventTouchUpInside];
  22. [self addSubview:self.growingButton];
  23. self.buttonSize = CGSizeMake(100, 100);
  24. [self setNeedsUpdateConstraints];
  25. return self;
  26. }
  27. - (void)updateConstraints {
  28. [super updateConstraints];
  29. [self.growingButton updateConstraints:^(MASConstraintMaker *make) {
  30. make.center.equalTo(self);
  31. make.width.equalTo(@(self.buttonSize.width));
  32. make.height.equalTo(@(self.buttonSize.height));
  33. }];
  34. }
  35. - (void)didTapGrowButton:(UIButton *)button {
  36. self.buttonSize = CGSizeMake(self.buttonSize.width * 1.1, self.buttonSize.height * 1.1);
  37. [self setNeedsUpdateConstraints];
  38. [self updateConstraintsIfNeeded];
  39. [UIView animateWithDuration:0.4 animations:^{
  40. [self layoutIfNeeded];
  41. }];
  42. }
  43. @end