@@ -46,30 +46,11 @@ - (void)didTap {
46
46
47
47
MDMMotionAnimator *animator = [[MDMMotionAnimator alloc ] init ];
48
48
animator.shouldReverseValues = !_expanded;
49
+ animator.beginFromCurrentState = YES ;
49
50
50
- if (_expanded) {
51
- // We can't easily animate the hiding of the navigation bar because UIKit sets the hidden
52
- // property on the navigation bar immediately if animated: is false.
53
- [self .navigationController setNavigationBarHidden: true animated: true ];
54
-
55
- } else {
56
- // Cache the previous value because we want to restore it in a moment.
57
- BOOL wasReversingValues = animator.shouldReverseValues ;
58
- animator.shouldReverseValues = false ;
59
-
60
- // Let UIKit do the layout calculations for us.
61
- CGFloat currentPosition = self.navigationController .navigationBar .layer .position .y ;
62
- [self .navigationController setNavigationBarHidden: false animated: false ];
63
- CGFloat desiredPosition = self.navigationController .navigationBar .layer .position .y ;
64
-
65
- [animator animateWithTiming: timing.navigationBarY
66
- toLayer: self .navigationController.navigationBar.layer
67
- withValues: @[ @(currentPosition), @(desiredPosition) ]
68
- keyPath: MDMKeyPathY];
69
-
70
- // Restore the previous value.
71
- animator.shouldReverseValues = wasReversingValues;
72
- }
51
+ [animator animateWithTiming: timing.navigationBarY animations: ^{
52
+ [self .navigationController setNavigationBarHidden: _expanded animated: YES ];
53
+ }];
73
54
74
55
CGRect chipFrame = [self frameForChip ];
75
56
CGRect headerFrame = [self frameForHeader ];
0 commit comments