IOS 7 UINavigationController NavBar for each color animation of the controller

Is there a way to have different barTintColor from UINavigationController UINavigationBar on different pushed controllers with smooth color transition animation ?

I want to have a smooth hue color animation of the UINavigationBar during the push / pop animation of the UINavigationController and ideally also an interactive pop panel (gesture-based pop controller).

Why do I need it? I would like to have 1 controller in the navigation stack to have a different hue color indicating the status of a task (red / green, etc.).

What I have tried so far:

  • viewWillAppear (view life cycle), but there is no way to animate barTintColor (e.g. setBarTintColor:animated:
  • To change barTintColor in the [UIView animation...] block, but it just strangely animates the frame of (possibly) some background layer instead of a smooth color transition.
  • To change barTintColor to a [UIView transitionWithView:...] block using the UIViewAnimationOptionTransitionCrossDissolve , but this will not change the animation. It just instantly changes to a new hue color after the animation
  • I came up with the idea of โ€‹โ€‹introducing a new iOS 7 custom transition that calculated and changed the color of the navbar at runtime, but that seems like a big kink (especially if I want the look of the animation to be everywhere)

Thanks to everyone for any ideas and answers.

+6
source share
1 answer

You can get this using the UIViewControllerTransitionCoordinator .

  • Copy the sample code into AController and customize the colors.
  • Copy the sample code into BController and customize the colors.
  • What is it! During the UINavigationController push / pop AController style will fade in / out of the BController style.

Code example:

 -(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]; } 
+26
source

Source: https://habr.com/ru/post/955577/


All Articles