GDNavigationController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // GDNavigationController.m
  3. // LNMobileProject
  4. //
  5. //
  6. #import "GDNavigationController.h"
  7. //#import "UIImage+ImageWithColor.h"
  8. @interface GDNavigationController () <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
  9. @end
  10. @implementation GDNavigationController
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. self.delegate = self;
  14. [self setupNavigationBar];
  15. }
  16. - (void)viewDidAppear:(BOOL)animated{
  17. [super viewDidAppear:animated];
  18. }
  19. - (void)setupNavigationBar {
  20. // 设置left right NavItem
  21. [[UINavigationBar appearance] setTintColor:UIColor.whiteColor];
  22. [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UINavigationController class]]] setTitleTextAttributes:@{NSForegroundColorAttributeName: UIColor.whiteColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal];
  23. // 设置标题的颜色
  24. [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.whiteColor,NSFontAttributeName:[UIFont systemFontOfSize:18 weight:UIFontWeightBold]}];
  25. // 导航栏背景图片
  26. // [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:NaviBarBgColor] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  27. // 导航栏背景色
  28. [[UINavigationBar appearance] setBarTintColor:UIColor.blackColor];
  29. [[UINavigationBar appearance] setTranslucent:NO];
  30. // 导航栏分隔线
  31. // [[UINavigationBar appearance] setShadowImage:[UIImage imageWithColor:UIColor.clearColor size:CGSizeMake(1, 1.0 / UIScreen.mainScreen.scale)]];
  32. // 自定义返回按钮 图片
  33. UIImage *backImage = [[UIImage imageNamed:@"f_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  34. [[UINavigationBar appearance] setBackIndicatorImage:backImage];
  35. [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backImage];
  36. if (@available(iOS 15.0, *)) {
  37. UINavigationBar *navigationBar = [UINavigationBar appearance];
  38. UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init];
  39. scrollEdgeAppearance.backgroundColor = UIColor.blackColor;
  40. [scrollEdgeAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.whiteColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];
  41. scrollEdgeAppearance.backButtonAppearance.normal.titlePositionAdjustment= UIOffsetMake(-1000, 0);
  42. scrollEdgeAppearance.shadowColor = [UIColor clearColor];
  43. navigationBar.scrollEdgeAppearance = scrollEdgeAppearance;
  44. navigationBar.standardAppearance = scrollEdgeAppearance;
  45. }
  46. }
  47. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
  48. // 登录拦截
  49. // NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)];
  50. // NSArray *names = @[];
  51. // if ([names indexOfObject:vc_name] != NSNotFound && ![SPMobileApplication sharedInstance].isLogined) {
  52. // [[AppDelegate sharedAppDelegate] presentLogin];
  53. // return;
  54. // }
  55. // 隐藏TabBar
  56. if (self.viewControllers.count >= 1) {
  57. viewController.hidesBottomBarWhenPushed = YES;
  58. }else{
  59. }
  60. [super pushViewController:viewController animated:animated];
  61. }
  62. - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  63. // NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)];
  64. //
  65. // NSArray *names = @[@"JXDetailViewController",@"JXShortDramaViewController",@"NewHomeViewController",@"MineViewController"];
  66. //
  67. // if ([names indexOfObject:vc_name] != NSNotFound) {
  68. [navigationController setNavigationBarHidden:YES animated:animated];
  69. // }
  70. // else {
  71. // [navigationController setNavigationBarHidden:NO animated:animated];
  72. // }
  73. }
  74. - (void)navigationController:(UINavigationController *)navigationController
  75. didShowViewController:(UIViewController *)viewController
  76. animated:(BOOL)animate
  77. {
  78. NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)];
  79. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  80. if (self.viewControllers.count > 1) {
  81. NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)];
  82. if ([vc_name isEqualToString:@""]) {
  83. self.interactivePopGestureRecognizer.enabled = NO;
  84. }else{
  85. self.interactivePopGestureRecognizer.enabled = YES;
  86. self.interactivePopGestureRecognizer.delegate = (id)viewController;
  87. }
  88. } else {
  89. self.interactivePopGestureRecognizer.enabled = NO;
  90. }
  91. }
  92. }
  93. - (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
  94. if (self.viewControllers.count > 1) {
  95. self.topViewController.hidesBottomBarWhenPushed = NO;
  96. }
  97. return [super popToRootViewControllerAnimated:animated];
  98. }
  99. @end