- Add Show/Hide Animation

This commit is contained in:
Giuseppe Nucifora 2015-07-22 17:43:49 +02:00
parent f217268512
commit 1797083a99

View File

@ -20,6 +20,9 @@
@property (nonatomic, strong) TabBarPickerSubItemsView *subItemSelector; @property (nonatomic, strong) TabBarPickerSubItemsView *subItemSelector;
@property (nonatomic) BOOL show; @property (nonatomic) BOOL show;
@property (nonatomic, assign) BOOL didSetupConstraints; @property (nonatomic, assign) BOOL didSetupConstraints;
@property (nonatomic, strong) NSLayoutConstraint *showConstraint;
@property (nonatomic, strong) NSLayoutConstraint *hideConstraint;
@end @end
@ -145,7 +148,7 @@
case TabBarPickerPositionBottom: case TabBarPickerPositionBottom:
default:{ default:{
[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]; _hideConstraint = [self autoPinEdgeToSuperviewMargin:ALEdgeBottom];
[self autoSetDimension:ALDimensionHeight toSize:44]; [self autoSetDimension:ALDimensionHeight toSize:44];
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation]; [self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation];
[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]; [self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical];
@ -159,13 +162,19 @@
break; break;
} }
[_subItemSelector layoutSubviews]; [_subItemSelector layoutSubviews];
_didSetupConstraints = YES; _didSetupConstraints = YES;
[self updateConstraintsIfNeeded]; [self updateConstraintsIfNeeded];
} }
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self show];
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self hide];
});
} }
- (void) setPosition:(TabBarPickerPosition)position { - (void) setPosition:(TabBarPickerPosition)position {
@ -204,21 +213,44 @@
[self setNeedsUpdateConstraints]; [self setNeedsUpdateConstraints];
[self updateConstraintsIfNeeded]; [self updateConstraintsIfNeeded];
[UIView animateWithDuration:1.0 [UIView animateWithDuration:4
delay:0.0 delay:0.0
options:UIViewAnimationOptionCurveEaseInOut usingSpringWithDamping:0.6
initialSpringVelocity:0
options:0
animations:^{ animations:^{
[self layoutIfNeeded]; // this is what actually causes the views to animate to their new layout [_hideConstraint autoRemove];
_showConstraint = [self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:_subItemSelector.frame.size.height];
} }
completion:^(BOOL finished) { completion:^(BOOL finished) {
// Run the animation again in the other direction // Run the animation again in the other direction
}]; }];
} }
} }
- (void) hide { - (void) hide {
if (_show) {
_show = NO;
[self setNeedsUpdateConstraints];
[self updateConstraintsIfNeeded];
[UIView animateWithDuration:4
delay:0.0
usingSpringWithDamping:0.6
initialSpringVelocity:0
options:0
animations:^{
[_showConstraint autoRemove];
_hideConstraint = [self autoPinEdgeToSuperviewMargin:ALEdgeBottom];
}
completion:^(BOOL finished) {
// Run the animation again in the other direction
}];
}
} }
#pragma mark TabBarPickerSubItemsViewDelegate #pragma mark TabBarPickerSubItemsViewDelegate