| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- //
- // RANavigationController.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/8/31.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "TFNavigationController.h"
- #import "RASingleton.h"
- #import "const.h"
- #import "RAUtils.h"
- //#import "RAOrderDetailViewController.h"
- @interface TFNavigationController ()
- {
- CAGradientLayer *_gradientLayer;
- UIView *_barBackgroundView, *_gradientView;
- }
- @end
- @implementation TFNavigationController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self _configAppearance];
- [self registNotification];
-
- // _gradientLayer.locations = @[@0,@0.2];
-
-
- }
- //-(void)viewWillAppear:(BOOL)animated
- //{
- // [super viewWillAppear: animated];
- //}
- //-(void) viewDidLayoutSubviews
- //{
- // [super viewDidLayoutSubviews];
- //
- //
- //}
- -(void) initglayer
- {
- // return;
-
- if(_gradientView!=nil)
- return;
-
- _gradientLayer = [CAGradientLayer layer];
-
- UIColor *orangeWhiteColor = PrimaryColor1;
- UIColor *orangeColor = PrimaryColor0;
- _gradientLayer.colors = @[(__bridge id)orangeColor.CGColor, (__bridge id)orangeWhiteColor.CGColor];
-
- _gradientLayer.startPoint = CGPointMake(0, 0);
- _gradientLayer.endPoint = CGPointMake(1, 0);
- _barBackgroundView = [self.navigationBar.subviews objectAtIndex:0];
-
- _gradientView = [UIView new];
- _gradientView.frame = _barBackgroundView.bounds;
- _gradientLayer.frame = _gradientView.bounds;
-
- [_gradientView.layer addSublayer:_gradientLayer];
- [_barBackgroundView addSubview:_gradientView];
-
- [_barBackgroundView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:(__bridge void * _Nullable)(self)];
- }
- -(void) viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- [self initglayer];
- }
- -(void) setupColor
- {
- [self initglayer];
- if(RASingleton.sharedInstance.isLogin)
- {
- _gradientView.hidden=false;
- [self.navigationBar setTintColor:WhiteColor]; // BarItem颜色
- [self setNeedsStatusBarAppearanceUpdate];
- }
- else
- {
- _gradientView.hidden=true;
- [self.navigationBar setTintColor:nil]; // BarItem颜色
- [self setNeedsStatusBarAppearanceUpdate];
- }
-
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
- if (context == (__bridge void * _Nullable)(self)) {
-
- _gradientView.frame = _barBackgroundView.bounds;
- _gradientLayer.frame = _gradientView.bounds;
- }
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [_barBackgroundView removeObserver:self forKeyPath:@"frame"];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- if(RASingleton.sharedInstance.isLogin)
- return UIStatusBarStyleLightContent;
- else
- return UIStatusBarStyleDefault;
- }
- - (void)_configAppearance {
-
- [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:WhiteColor}]; // Title Color
- // [self.navigationBar setTintColor:WhiteColor]; // BarItem颜色
- self.navigationBar.barTintColor = WhiteColor; // 背景色
- self.navigationBar.translucent = YES;
-
- // 去除Bar黑色分割线
- self.navigationBar.shadowImage = [UIImage new];
- [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
- }
- - (void)registNotification {
- // return;
- // [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveHandleKickoutNotification:) name:RA_NOTIFICATION_KICKOUT object:nil];
- }
- //
- - (void)receiveHandleKickoutNotification:(NSNotification *)notification {
- [self popToRootViewControllerAnimated:true];
- [RASingleton.sharedInstance logout];
- [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGOUT object:nil];
- NSLog(@"show kick out alert %@",notification.object);
- [RAUtils message_alert:notification.object title:@"Warrning" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
- // [vc.navigationController popToRootViewControllerAnimated:true];
- } completion:^{
-
-
- }];
-
-
-
- // return;
- // NSDictionary *userInfo = notification.userInfo;
- // NSDictionary *aps = [userInfo objectForKey:@"aps"];
- // NSString *orderID = [aps objectForKey:@"order-id"];
- // NSInteger orderType = [[aps objectForKey:@"order-type"] integerValue];
- // NSString *orderType2 = [aps objectForKey:@"order-type2"];
- // NSString *statusNo = [aps objectForKey:@"status-no"];
- // if (!orderType2) {
- // orderType2 = @"";
- // }
- //
- // BOOL required = [[aps objectForKey:@"required"] boolValue];
- // BOOL go2Detail = [[userInfo objectForKey:@"go2Detail"] boolValue];
- //
- //// [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
- // if (orderID) {
- //
- // if (go2Detail) {
- //
- // [self pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
- // } else {
- // NSString *msg = [aps objectForKey:@"message"];
- // if (msg.length == 0) {
- // msg = [NSString localizedStringWithFormat:NSLocalizedString(@"%@ status changed,view detail?", nil),orderID];
- // }
- //
- // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Message", nil) message:msg preferredStyle:UIAlertControllerStyleAlert];
- //
- // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- //
- // }];
- //
- // __weak typeof(self) weakSelf = self;
- // UIAlertAction *detailAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // [weakSelf pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
- // }];
- //
- // if (!required) {
- // [alertVC addAction:cancelAction];
- // }
- // [alertVC addAction:detailAction];
- //
- // [self presentViewController:alertVC animated:YES completion:nil];
- // }
- //
- // }
- }
- //
- //- (void)pushDetailViewControllerForOrderID:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 statusNo:(NSString *)statusNo {
- // return;
- ////
- //// if (!orderID) {
- //// return;
- //// }
- //// RAOrderDetailViewController *detailVC = [RAOrderDetailViewController viewControllerFromStoryboard];
- //// detailVC.orderID = orderID;
- //// detailVC.orderType = type;
- //// detailVC.orderType2 = type2;
- //// detailVC.status_no = statusNo;
- //// [self pushViewController:detailVC animated:YES];
- //}
- @end
|