0

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

Erik
  • 2,500
  • 6
  • 28
  • 49
  • this problem is a pain in the ass. really I think the best solution is just to slide in the new one ("over" the old one) – Fattie Oct 21 '14 at 13:41
  • @JoeBlow A solution would be to switch to modally present it instead of pushing it. What do you think is the best solution? – Erik Oct 21 '14 at 17:49
  • FTR did you try this . . http://stackoverflow.com/a/1618557/294884 – Fattie Oct 22 '14 at 07:13
  • @JoeBlow Tried, but you just don't get that "premium feel" with that solution :/ – Erik Oct 22 '14 at 14:17

1 Answers1

1

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

Erik
  • 2,500
  • 6
  • 28
  • 49
  • @JoeBlow Wouldn't another solution be to make the NavigationBar transparent at all times, and set the NavigationBar's tint using a background ImageView rather than the tint property? Perhaps that would achieve an even smoother animation? I'll try to implement that tomorrow – Erik Nov 15 '14 at 22:33
  • Hi Erik - yea, that does seem like a pretty good idea. We're really sort of "fighting apple" on this: they will/are clearly making small change after small change to "how those bars work" on each new ios update; it's gonna be tricky to really keep it working! :O But yeah that seems like a nice idea... – Fattie Nov 17 '14 at 04:52
  • what if you made an orange image, set the height of it according to the size of the NavigationBar and set a Constraint with 0 space to the top SuperView? And a scale-to-fill mode, would that work? @JoeBlow – Erik Nov 17 '14 at 11:36
  • @JoeBlow do you have an idea on how to put a UIImageView behind the NavigationBar? – Erik Nov 19 '14 at 20:23
  • I'm afraid I DO NOT; I'd ask another question on that – Fattie Nov 20 '14 at 04:14