TFNavigationController.m 7.1 KB

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