Reputation: 2530
I'm trying to push from one VC to another - which is 0 problem, but VC1 has a orange NavigationBar while VC2 has a completely transparent NavigationBar. I would like to transition smoothly between the 2 different NavigationBars during the push segue. However, at the moment - it comes this blackish sliding bar and the color isn't transitioning nicely. This is my code:
VC1 viewWillAppear:
// Set the BarTintColor to translucent and text colors to white
[UIView animateWithDuration:0.5 animations:^{
self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
}];
VC 2 viewWillAppear:
// Make the NavigationBar transparent
[UIView animateWithDuration:0.5 animations:^{
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
}];
How can I solve this in a more efficient and better way?
Thanks! Erik
Upvotes: 0
Views: 126
Reputation: 2530
Solved it like this:
// Make the NavigationBar transparent
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
[UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:.8 initialSpringVelocity:1.5 options:UIViewAnimationOptionTransitionNone animations:^{
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
}completion:^(BOOL finished) {
}];
Setting the clearColor outside of the animateWithDuration block made the animation a billion times smoother. Now it animates nicely away
Upvotes: 1