NSScreencast Episode #135 Animating Constraints
Animating Constraints - NSScreencast
動的にAutoLayoutを設定しアニメーションする
以前のプロジェクトの続き
- Add properties for constraints and views
- @property (nonatomic, strong) NSLayoutConstraint *leftWidthConstraint;
- @property (nonatomic, strong) UIView *leftView;
- @property (nonatomic, strong) UIView *headlineView;
- @property (nonatomic) BOOL expanded;
- Extract constraint part into method
- leftWidthConstraintWithMultiplier:(CGFloat)multiplier
- return [NSLayoutConstraint constraintWithItem:self.leftView
- viewDidLoad
- self.leftWidthConstraint = [self leftWidthConstraintWithMultiplier:0.3];
- [self.view addConstraint:self.leftWidthConstraint];
- leftWidthConstraintWithMultiplier:(CGFloat)multiplier
- On button tap, toggle flag, remove/readd constraints
- onButtonTap:(id)sender
- CGFloat multiplier = self.expanded ? 0.3 : 0.7;
- self.expanded = !self.expanded;
- [self.view removeConstraint:self.leftWidthConstraint];
- self.leftWidthConstraint = [self leftWidthConstraintWithMultiplier:multiplier];
- [self.view addConstraint:self.leftWidthConstraint];
- [UIView animateWithDuration:0.5
- spring like animation
- onButtonTap:(id)sender
- leftViewをタップすると画面の下から別のaccessoryViewが出てくる
- properties
- @property (nonatomic, strong) UIView *accessoryView;
- @property (nonatomic, strong) NSArray *verticalConstraints;
- @property (nonatomic) BOOL accessoryVisible
- verticalConstraintsWithAccessoryViewVisible:(BOOL)visible
- "V:|-(topPadding)-[headlineView(headlineViewHeight)]-[leftView]-(accessoryPadding)-[_accessoryView(accessoryHeight)]-|"
- views:NSDictionaryOfVariableBindings(headlineView, leftView, _accessoryView)];
- properties
後半細かいところはよく分からない