Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit f505ecf

Browse files
authored
Make use of the implicit animator in the example. (#79)
This allows us to animate the appearance/disappearance of the navigation bar using specific timings.
1 parent 3a563c5 commit f505ecf

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

examples/CalendarCardExpansionExample.m

+4-23
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,11 @@ - (void)didTap {
4646

4747
MDMMotionAnimator *animator = [[MDMMotionAnimator alloc] init];
4848
animator.shouldReverseValues = !_expanded;
49+
animator.beginFromCurrentState = YES;
4950

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+
}];
7354

7455
CGRect chipFrame = [self frameForChip];
7556
CGRect headerFrame = [self frameForHeader];

0 commit comments

Comments
 (0)