Advertisement
Guest User

new version

a guest
Feb 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #import <UIKit/UIKit.h>
  3.  
  4. @interface AVCNavigationController : UINavigationController
  5.  
  6. - (void)setNavBarBackgroundVisible:(BOOL)navBarVisible animated:(BOOL)animated;
  7.  
  8. @property (nonatomic)   BOOL    navBarBackgroundVisible;
  9.  
  10. /// should be called from viewWillAppear(); 'vc' is an optional parameters
  11. - (void)setBackgroundColor:(UIColor *)barTint animatedUsing:(UIViewController *)vc;
  12.  
  13. - (UIColor *)previousBarTintColor;
  14.  
  15. @end
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. #import "AVCNavigationController.h"
  24.  
  25. #import "UIImage+ImageWithColor.h"
  26. #import "UIColor+AVCColors.h"
  27.  
  28. @interface AVCNavigationController ()
  29.  
  30. @property (nonatomic)   UIColor *   barTintColor;   //!< last set bar tint color, gets pushed onto the stack in pushViewController()
  31.  
  32. @property (nonatomic)   NSMutableArray< UIColor* >  *   barTintColorStack;  //!< so that we can peek at previous bar tint color for smooth transitions
  33.  
  34. @end
  35.  
  36. @implementation AVCNavigationController
  37.  
  38. + (void)initialize
  39. {
  40.     [[UINavigationBar appearance] setBarTintColor:[UIColor avc_greenColor]];
  41.     [[UINavigationBar appearance] setTranslucent:NO];
  42. }
  43.  
  44. - (void)viewDidLoad
  45. {
  46.     [super viewDidLoad];
  47.  
  48.     self.navigationBar.translucent = NO;
  49.    
  50.     _barTintColor = [UIColor avc_greenColor];
  51.     _barTintColorStack = [NSMutableArray< UIColor* > arrayWithCapacity:4];
  52. }
  53.  
  54. - (void)setNavBarBackgroundVisible:(BOOL)navBarBackgroundVisible
  55. {
  56.     [self setNavBarBackgroundVisible:navBarBackgroundVisible animated:NO];
  57. }
  58.  
  59. - (void)setNavBarBackgroundVisible:(BOOL)navBarBackgroundVisible animated:(BOOL)animated
  60. {
  61.     _navBarBackgroundVisible = navBarBackgroundVisible;
  62.     printf("❀️INFO: setNavBarBackgroundVisible: %d, animated=%d\n",navBarBackgroundVisible, animated);
  63. }
  64.  
  65. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
  66. {
  67.     [_barTintColorStack addObject:_barTintColor];
  68.  
  69.     [super pushViewController:viewController animated:animated];
  70. }
  71.  
  72. - (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated
  73. {
  74.     UIViewController *vc = [super popViewControllerAnimated:animated];
  75.  
  76.     [_barTintColorStack removeLastObject];
  77.  
  78.     return vc;
  79. }
  80.  
  81. - (void)setBackgroundColor:(UIColor *)barTint animatedUsing:(UIViewController *)vc
  82. {
  83.     _barTintColor = barTint;
  84.  
  85.     if( vc )
  86.     {
  87.         [vc.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  88.             //
  89.             self.navigationBar.barTintColor = barTint;
  90.            
  91.         } completion: nil];
  92.     }
  93.     else
  94.     {
  95.         self.navigationBar.barTintColor = barTint;
  96.     }
  97. }
  98.  
  99. - (UIColor *)previousBarTintColor
  100. {
  101.     NSAssert(_barTintColorStack.count, @"empty stack!");
  102.    
  103.     UIColor *previousColor = _barTintColorStack.lastObject;
  104.    
  105.     return previousColor;
  106. }
  107.  
  108. - (UIColor *)currentBarTintColor
  109. {
  110.     return _barTintColorStack.lastObject;
  111. }
  112.  
  113. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement