// // GDNavigationController.m // LNMobileProject // // #import "GDNavigationController.h" //#import "UIImage+ImageWithColor.h" @interface GDNavigationController () @end @implementation GDNavigationController - (void)viewDidLoad { [super viewDidLoad]; self.delegate = self; [self setupNavigationBar]; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; } - (void)setupNavigationBar { // 设置left right NavItem [[UINavigationBar appearance] setTintColor:UIColor.whiteColor]; [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UINavigationController class]]] setTitleTextAttributes:@{NSForegroundColorAttributeName: UIColor.whiteColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal]; // 设置标题的颜色 [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.whiteColor,NSFontAttributeName:[UIFont systemFontOfSize:18 weight:UIFontWeightBold]}]; // 导航栏背景图片 // [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:NaviBarBgColor] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; // 导航栏背景色 [[UINavigationBar appearance] setBarTintColor:UIColor.blackColor]; [[UINavigationBar appearance] setTranslucent:NO]; // 导航栏分隔线 // [[UINavigationBar appearance] setShadowImage:[UIImage imageWithColor:UIColor.clearColor size:CGSizeMake(1, 1.0 / UIScreen.mainScreen.scale)]]; // 自定义返回按钮 图片 UIImage *backImage = [[UIImage imageNamed:@"f_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [[UINavigationBar appearance] setBackIndicatorImage:backImage]; [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backImage]; if (@available(iOS 15.0, *)) { UINavigationBar *navigationBar = [UINavigationBar appearance]; UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init]; scrollEdgeAppearance.backgroundColor = UIColor.blackColor; [scrollEdgeAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.whiteColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}]; scrollEdgeAppearance.backButtonAppearance.normal.titlePositionAdjustment= UIOffsetMake(-1000, 0); scrollEdgeAppearance.shadowColor = [UIColor clearColor]; navigationBar.scrollEdgeAppearance = scrollEdgeAppearance; navigationBar.standardAppearance = scrollEdgeAppearance; } } - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { // 登录拦截 // NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)]; // NSArray *names = @[]; // if ([names indexOfObject:vc_name] != NSNotFound && ![SPMobileApplication sharedInstance].isLogined) { // [[AppDelegate sharedAppDelegate] presentLogin]; // return; // } // 隐藏TabBar if (self.viewControllers.count >= 1) { viewController.hidesBottomBarWhenPushed = YES; }else{ } [super pushViewController:viewController animated:animated]; } - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)]; // // NSArray *names = @[@"JXDetailViewController",@"JXShortDramaViewController",@"NewHomeViewController",@"MineViewController"]; // // if ([names indexOfObject:vc_name] != NSNotFound) { [navigationController setNavigationBarHidden:YES animated:animated]; // } // else { // [navigationController setNavigationBarHidden:NO animated:animated]; // } } - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animate { NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)]; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { if (self.viewControllers.count > 1) { NSString *vc_name = [NSString stringWithUTF8String:object_getClassName(viewController)]; if ([vc_name isEqualToString:@""]) { self.interactivePopGestureRecognizer.enabled = NO; }else{ self.interactivePopGestureRecognizer.enabled = YES; self.interactivePopGestureRecognizer.delegate = (id)viewController; } } else { self.interactivePopGestureRecognizer.enabled = NO; } } } - (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated { if (self.viewControllers.count > 1) { self.topViewController.hidesBottomBarWhenPushed = NO; } return [super popToRootViewControllerAnimated:animated]; } @end