| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // GDNavigationController.m
- // LNMobileProject
- //
- //
- #import "GDNavigationController.h"
- //#import "UIImage+ImageWithColor.h"
- @interface GDNavigationController () <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
- @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
|