| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //
- // RANavigationController.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/8/31.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "RANavigationController.h"
- #import "RAOrderDetailViewController.h"
- @interface RANavigationController ()
- {
- CAGradientLayer *_gradientLayer;
- UIView *_barBackgroundView, *_gradientView;
- }
- @end
- @implementation RANavigationController
- - (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) viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- if(_gradientView!=nil)
- return;
-
- _gradientLayer = [CAGradientLayer layer];
-
- UIColor *orangeWhiteColor = ApexDriverOrangeWhiteColor;
- UIColor *orangeColor = ApexDriverOrangeColor;
- _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)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 {
- return UIStatusBarStyleLightContent;
- }
- - (void)_configAppearance {
-
- [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ApexDriverWhiteColor}]; // Title Color
- [self.navigationBar setTintColor:ApexDriverWhiteColor]; // BarItem颜色
- self.navigationBar.barTintColor = ApexDriverOrangeColor; // 背景色
- self.navigationBar.translucent = NO;
-
- // 去除Bar黑色分割线
- self.navigationBar.shadowImage = [UIImage new];
- [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
- }
- - (void)registNotification {
- // [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveHandleOrderNotification:) name:RANotificationHandleOrder object:nil];
- }
- - (void)receiveHandleOrderNotification:(NSNotification *)notification {
-
- 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 stringWithFormat:@"%@ status changed,view detail?",orderID];
- }
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Message" message:msg preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- __weak typeof(self) weakSelf = self;
- UIAlertAction *detailAction = [UIAlertAction actionWithTitle:@"Ok" 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 {
-
- 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
|