TFNavigationController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 "TFNavigationController.h"
  9. #import "RASingleton.h"
  10. #import "const.h"
  11. //#import "RAOrderDetailViewController.h"
  12. @interface TFNavigationController ()
  13. {
  14. CAGradientLayer *_gradientLayer;
  15. UIView *_barBackgroundView, *_gradientView;
  16. }
  17. @end
  18. @implementation TFNavigationController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self _configAppearance];
  23. [self registNotification];
  24. // _gradientLayer.locations = @[@0,@0.2];
  25. }
  26. //-(void)viewWillAppear:(BOOL)animated
  27. //{
  28. // [super viewWillAppear: animated];
  29. //}
  30. //-(void) viewDidLayoutSubviews
  31. //{
  32. // [super viewDidLayoutSubviews];
  33. //
  34. //
  35. //}
  36. -(void) initglayer
  37. {
  38. if(_gradientView!=nil)
  39. return;
  40. _gradientLayer = [CAGradientLayer layer];
  41. UIColor *orangeWhiteColor = PrimaryColor1;
  42. UIColor *orangeColor = PrimaryColor0;
  43. _gradientLayer.colors = @[(__bridge id)orangeColor.CGColor, (__bridge id)orangeWhiteColor.CGColor];
  44. _gradientLayer.startPoint = CGPointMake(0, 0);
  45. _gradientLayer.endPoint = CGPointMake(1, 0);
  46. _barBackgroundView = [self.navigationBar.subviews objectAtIndex:0];
  47. _gradientView = [UIView new];
  48. _gradientView.frame = _barBackgroundView.bounds;
  49. _gradientLayer.frame = _gradientView.bounds;
  50. [_gradientView.layer addSublayer:_gradientLayer];
  51. [_barBackgroundView addSubview:_gradientView];
  52. [_barBackgroundView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:(__bridge void * _Nullable)(self)];
  53. }
  54. -(void) viewDidAppear:(BOOL)animated
  55. {
  56. [super viewDidAppear:animated];
  57. [self initglayer];
  58. }
  59. -(void) setupColor
  60. {
  61. [self initglayer];
  62. if(RASingleton.sharedInstance.isLogin)
  63. {
  64. _gradientView.hidden=false;
  65. [self.navigationBar setTintColor:WhiteColor]; // BarItem颜色
  66. [self setNeedsStatusBarAppearanceUpdate];
  67. }
  68. else
  69. {
  70. _gradientView.hidden=true;
  71. [self.navigationBar setTintColor:nil]; // BarItem颜色
  72. [self setNeedsStatusBarAppearanceUpdate];
  73. }
  74. }
  75. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  76. if (context == (__bridge void * _Nullable)(self)) {
  77. _gradientView.frame = _barBackgroundView.bounds;
  78. _gradientLayer.frame = _gradientView.bounds;
  79. }
  80. }
  81. - (void)dealloc {
  82. [[NSNotificationCenter defaultCenter] removeObserver:self];
  83. [_barBackgroundView removeObserver:self forKeyPath:@"frame"];
  84. }
  85. - (void)didReceiveMemoryWarning {
  86. [super didReceiveMemoryWarning];
  87. // Dispose of any resources that can be recreated.
  88. }
  89. - (UIStatusBarStyle)preferredStatusBarStyle {
  90. if(RASingleton.sharedInstance.isLogin)
  91. return UIStatusBarStyleLightContent;
  92. else
  93. return UIStatusBarStyleDefault;
  94. }
  95. - (void)_configAppearance {
  96. [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:WhiteColor}]; // Title Color
  97. // [self.navigationBar setTintColor:WhiteColor]; // BarItem颜色
  98. self.navigationBar.barTintColor = WhiteColor; // 背景色
  99. self.navigationBar.translucent = NO;
  100. // 去除Bar黑色分割线
  101. self.navigationBar.shadowImage = [UIImage new];
  102. [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  103. }
  104. - (void)registNotification {
  105. return;
  106. // [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
  107. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveHandleOrderNotification:) name:RANotificationHandleOrder object:nil];
  108. }
  109. //
  110. //- (void)receiveHandleOrderNotification:(NSNotification *)notification {
  111. //
  112. // return;
  113. // NSDictionary *userInfo = notification.userInfo;
  114. // NSDictionary *aps = [userInfo objectForKey:@"aps"];
  115. // NSString *orderID = [aps objectForKey:@"order-id"];
  116. // NSInteger orderType = [[aps objectForKey:@"order-type"] integerValue];
  117. // NSString *orderType2 = [aps objectForKey:@"order-type2"];
  118. // NSString *statusNo = [aps objectForKey:@"status-no"];
  119. // if (!orderType2) {
  120. // orderType2 = @"";
  121. // }
  122. //
  123. // BOOL required = [[aps objectForKey:@"required"] boolValue];
  124. // BOOL go2Detail = [[userInfo objectForKey:@"go2Detail"] boolValue];
  125. //
  126. //// [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
  127. // if (orderID) {
  128. //
  129. // if (go2Detail) {
  130. //
  131. // [self pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
  132. // } else {
  133. // NSString *msg = [aps objectForKey:@"message"];
  134. // if (msg.length == 0) {
  135. // msg = [NSString localizedStringWithFormat:NSLocalizedString(@"%@ status changed,view detail?", nil),orderID];
  136. // }
  137. //
  138. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Message", nil) message:msg preferredStyle:UIAlertControllerStyleAlert];
  139. //
  140. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  141. //
  142. // }];
  143. //
  144. // __weak typeof(self) weakSelf = self;
  145. // UIAlertAction *detailAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  146. // [weakSelf pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
  147. // }];
  148. //
  149. // if (!required) {
  150. // [alertVC addAction:cancelAction];
  151. // }
  152. // [alertVC addAction:detailAction];
  153. //
  154. // [self presentViewController:alertVC animated:YES completion:nil];
  155. // }
  156. //
  157. // }
  158. //}
  159. //
  160. //- (void)pushDetailViewControllerForOrderID:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 statusNo:(NSString *)statusNo {
  161. // return;
  162. ////
  163. //// if (!orderID) {
  164. //// return;
  165. //// }
  166. //// RAOrderDetailViewController *detailVC = [RAOrderDetailViewController viewControllerFromStoryboard];
  167. //// detailVC.orderID = orderID;
  168. //// detailVC.orderType = type;
  169. //// detailVC.orderType2 = type2;
  170. //// detailVC.status_no = statusNo;
  171. //// [self pushViewController:detailVC animated:YES];
  172. //}
  173. @end