Last active
September 29, 2015 12:32
-
-
Save zvonicek/c7d6eccb67b7c69b5344 to your computer and use it in GitHub Desktop.
UINavigationBar styling between UINavigationController transitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
[[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { | |
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]]; | |
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}]; | |
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_navbar"] forBarMetrics:UIBarMetricsDefault]; | |
} completion:nil]; | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
[super viewWillDisappear:animated]; | |
[[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { | |
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; | |
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}]; | |
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; | |
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { | |
if ([context isCancelled]) { | |
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]]; | |
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}]; | |
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_navbar"] forBarMetrics:UIBarMetricsDefault]; | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment