Reputation: 7704
Is there any way to have different barTintColor
of UINavigationController
's UINavigationBar
on different pushed controllers with smooth color transition animation?
I'd like to have a smooth animation of UINavigationBar
's tint color during UINavigationController
's push/pop animation and ideally also interactive pop (gesture based controller pop).
Why do I need this? I'd like to have 1 controller in the navigation stack to have different tint color indicating status of some task (red / green etc.).
What I have tried so far:
viewWillAppear
(view lifecycle) methods, but there is no way to animate the barTintColor
(like setBarTintColor:animated:
)barTintColor
in [UIView animation...]
block, but that just weirdly animates frame of (probably) some background layer instead of smooth color transition.barTintColor
in [UIView transitionWithView:...]
block with UIViewAnimationOptionTransitionCrossDissolve
, but that does not animate change. Just instantly changes to new tint color after the animation durationThank you everyone for any ideas and answers
Upvotes: 6
Views: 2515
Reputation: 1174
You can get this by using UIViewControllerTransitionCoordinator
.
AController
and customize the colors.BController
and customize the colors.UINavigationController
's push/pop transition, the AController
's style will smoothly fade in/out to BController
's style.Example code:
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
// text color
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
// navigation items and bar button items color
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
// background color
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
} completion:nil];
}
Upvotes: 26