Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <UIKit/UIKit.h>
- @interface AVCNavigationController : UINavigationController
- - (void)setNavBarBackgroundVisible:(BOOL)navBarVisible animated:(BOOL)animated;
- @property (nonatomic) BOOL navBarBackgroundVisible;
- /// should be called from viewWillAppear(); 'vc' is an optional parameters
- - (void)setBackgroundColor:(UIColor *)barTint animatedUsing:(UIViewController *)vc;
- - (UIColor *)previousBarTintColor;
- @end
- #import "AVCNavigationController.h"
- #import "UIImage+ImageWithColor.h"
- #import "UIColor+AVCColors.h"
- @interface AVCNavigationController ()
- @property (nonatomic) UIColor * barTintColor; //!< last set bar tint color, gets pushed onto the stack in pushViewController()
- @property (nonatomic) NSMutableArray< UIColor* > * barTintColorStack; //!< so that we can peek at previous bar tint color for smooth transitions
- @end
- @implementation AVCNavigationController
- + (void)initialize
- {
- [[UINavigationBar appearance] setBarTintColor:[UIColor avc_greenColor]];
- [[UINavigationBar appearance] setTranslucent:NO];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.navigationBar.translucent = NO;
- _barTintColor = [UIColor avc_greenColor];
- _barTintColorStack = [NSMutableArray< UIColor* > arrayWithCapacity:4];
- }
- - (void)setNavBarBackgroundVisible:(BOOL)navBarBackgroundVisible
- {
- [self setNavBarBackgroundVisible:navBarBackgroundVisible animated:NO];
- }
- - (void)setNavBarBackgroundVisible:(BOOL)navBarBackgroundVisible animated:(BOOL)animated
- {
- _navBarBackgroundVisible = navBarBackgroundVisible;
- printf("β€οΈINFO: setNavBarBackgroundVisible: %d, animated=%d\n",navBarBackgroundVisible, animated);
- }
- - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
- {
- [_barTintColorStack addObject:_barTintColor];
- [super pushViewController:viewController animated:animated];
- }
- - (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated
- {
- UIViewController *vc = [super popViewControllerAnimated:animated];
- [_barTintColorStack removeLastObject];
- return vc;
- }
- - (void)setBackgroundColor:(UIColor *)barTint animatedUsing:(UIViewController *)vc
- {
- _barTintColor = barTint;
- if( vc )
- {
- [vc.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
- //
- self.navigationBar.barTintColor = barTint;
- } completion: nil];
- }
- else
- {
- self.navigationBar.barTintColor = barTint;
- }
- }
- - (UIColor *)previousBarTintColor
- {
- NSAssert(_barTintColorStack.count, @"empty stack!");
- UIColor *previousColor = _barTintColorStack.lastObject;
- return previousColor;
- }
- - (UIColor *)currentBarTintColor
- {
- return _barTintColorStack.lastObject;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement