RANavigationController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // RANavigationController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/8/31.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RANavigationController.h"
  9. #import "RAOrderDetailViewController.h"
  10. @interface RANavigationController ()
  11. {
  12. CAGradientLayer *_gradientLayer;
  13. UIView *_barBackgroundView, *_gradientView;
  14. }
  15. @end
  16. @implementation RANavigationController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. [self _configAppearance];
  21. [self registNotification];
  22. // _gradientLayer.locations = @[@0,@0.2];
  23. }
  24. //-(void)viewWillAppear:(BOOL)animated
  25. //{
  26. // [super viewWillAppear: animated];
  27. //}
  28. //-(void) viewDidLayoutSubviews
  29. //{
  30. // [super viewDidLayoutSubviews];
  31. //
  32. //
  33. //}
  34. -(void) viewDidAppear:(BOOL)animated
  35. {
  36. [super viewDidAppear:animated];
  37. if(_gradientView!=nil)
  38. return;
  39. _gradientLayer = [CAGradientLayer layer];
  40. UIColor *orangeWhiteColor = ApexDriverOrangeWhiteColor;
  41. UIColor *orangeColor = ApexDriverOrangeColor;
  42. _gradientLayer.colors = @[(__bridge id)orangeColor.CGColor, (__bridge id)orangeWhiteColor.CGColor];
  43. _gradientLayer.startPoint = CGPointMake(0, 0);
  44. _gradientLayer.endPoint = CGPointMake(1, 0);
  45. _barBackgroundView = [self.navigationBar.subviews objectAtIndex:0];
  46. _gradientView = [UIView new];
  47. _gradientView.frame = _barBackgroundView.bounds;
  48. _gradientLayer.frame = _gradientView.bounds;
  49. [_gradientView.layer addSublayer:_gradientLayer];
  50. [_barBackgroundView addSubview:_gradientView];
  51. [_barBackgroundView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:(__bridge void * _Nullable)(self)];
  52. }
  53. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  54. if (context == (__bridge void * _Nullable)(self)) {
  55. _gradientView.frame = _barBackgroundView.bounds;
  56. _gradientLayer.frame = _gradientView.bounds;
  57. }
  58. }
  59. - (void)dealloc {
  60. [[NSNotificationCenter defaultCenter] removeObserver:self];
  61. [_barBackgroundView removeObserver:self forKeyPath:@"frame"];
  62. }
  63. - (void)didReceiveMemoryWarning {
  64. [super didReceiveMemoryWarning];
  65. // Dispose of any resources that can be recreated.
  66. }
  67. - (UIStatusBarStyle)preferredStatusBarStyle {
  68. return UIStatusBarStyleLightContent;
  69. }
  70. - (void)_configAppearance {
  71. [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ApexDriverWhiteColor}]; // Title Color
  72. [self.navigationBar setTintColor:ApexDriverWhiteColor]; // BarItem颜色
  73. self.navigationBar.barTintColor = ApexDriverOrangeColor; // 背景色
  74. self.navigationBar.translucent = NO;
  75. // 去除Bar黑色分割线
  76. self.navigationBar.shadowImage = [UIImage new];
  77. [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  78. }
  79. - (void)registNotification {
  80. // [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
  81. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveHandleOrderNotification:) name:RANotificationHandleOrder object:nil];
  82. }
  83. - (void)receiveHandleOrderNotification:(NSNotification *)notification {
  84. NSDictionary *userInfo = notification.userInfo;
  85. NSDictionary *aps = [userInfo objectForKey:@"aps"];
  86. NSString *orderID = [aps objectForKey:@"order-id"];
  87. NSInteger orderType = [[aps objectForKey:@"order-type"] integerValue];
  88. NSString *orderType2 = [aps objectForKey:@"order-type2"];
  89. NSString *statusNo = [aps objectForKey:@"status-no"];
  90. if (!orderType2) {
  91. orderType2 = @"";
  92. }
  93. BOOL required = [[aps objectForKey:@"required"] boolValue];
  94. BOOL go2Detail = [[userInfo objectForKey:@"go2Detail"] boolValue];
  95. // [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
  96. if (orderID) {
  97. if (go2Detail) {
  98. [self pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
  99. } else {
  100. NSString *msg = [aps objectForKey:@"message"];
  101. if (msg.length == 0) {
  102. msg = [NSString localizedStringWithFormat:NSLocalizedString(@"%@ status changed,view detail?", nil),orderID];
  103. }
  104. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Message", nil) message:msg preferredStyle:UIAlertControllerStyleAlert];
  105. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  106. }];
  107. __weak typeof(self) weakSelf = self;
  108. UIAlertAction *detailAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  109. [weakSelf pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
  110. }];
  111. if (!required) {
  112. [alertVC addAction:cancelAction];
  113. }
  114. [alertVC addAction:detailAction];
  115. [self presentViewController:alertVC animated:YES completion:nil];
  116. }
  117. }
  118. }
  119. - (void)pushDetailViewControllerForOrderID:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 statusNo:(NSString *)statusNo {
  120. if (!orderID) {
  121. return;
  122. }
  123. RAOrderDetailViewController *detailVC = [RAOrderDetailViewController viewControllerFromStoryboard];
  124. detailVC.orderID = orderID;
  125. detailVC.orderType = type;
  126. detailVC.orderType2 = type2;
  127. detailVC.status_no = statusNo;
  128. [self pushViewController:detailVC animated:YES];
  129. }
  130. @end