CustomNavViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // CustomNavViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "CustomNavViewController.h"
  8. #import <UIImage+Color.h>
  9. @interface CustomNavViewController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>
  10. @end
  11. @implementation CustomNavViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. // Do any additional setup after loading the view.
  15. KSWeakSelf(weakSelf);
  16. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  17. self.interactivePopGestureRecognizer.delegate = weakSelf;
  18. self.delegate = weakSelf;
  19. if (@available(iOS 13.0, *)) {
  20. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  21. [appearance configureWithOpaqueBackground];
  22. // 去掉半透明效果
  23. appearance.backgroundEffect = nil;
  24. // 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
  25. appearance.shadowImage = [UIImage imageWithColor:[UIColor clearColor]];
  26. appearance.backgroundColor = [UIColor whiteColor];
  27. [appearance setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]}];
  28. self.navigationBar.standardAppearance = appearance;
  29. self.navigationBar.scrollEdgeAppearance = appearance;
  30. }
  31. else {
  32. [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
  33. UINavigationBar *navBar = [UINavigationBar appearance];
  34. [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]}];
  35. [navBar setBarTintColor:[UIColor whiteColor]];
  36. }
  37. self.view.backgroundColor = HexRGB(0xf6f8f9);
  38. }
  39. }
  40. - (UIStatusBarStyle)preferredStatusBarStyle {
  41. return UIStatusBarStyleDefault;
  42. }
  43. #pragma mark - UIGestureRecognizerDelegate
  44. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
  45. if (self.viewControllers.count <= 1) {
  46. return NO;
  47. }
  48. return YES;
  49. }
  50. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  51. return YES;
  52. }
  53. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  54. if ([self.viewControllers indexOfObject:self] == 0) {
  55. return YES;
  56. }
  57. return [gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]];
  58. }
  59. #pragma mark - Super class
  60. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
  61. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
  62. self.interactivePopGestureRecognizer.enabled = NO;
  63. }
  64. //如果现在push的不是栈顶控制器,那么久隐藏tabbar工具条
  65. if (self.childViewControllers.count >= 1) {
  66. viewController.hidesBottomBarWhenPushed = YES;
  67. }
  68. [super pushViewController:viewController animated:animated];
  69. }
  70. - (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
  71. self.visibleViewController.is_poppingToRoot = YES;
  72. if (self.viewControllers.count > 1) {
  73. self.topViewController.hidesBottomBarWhenPushed = NO;
  74. }
  75. NSArray<__kindof UIViewController *> *viewControllers = [super popToRootViewControllerAnimated:animated];
  76. // self.viewControllers has two items here on iOS14
  77. return viewControllers;
  78. }
  79. #pragma mark - UINavigationControllerDelegate
  80. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  81. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)] && ![viewController isKindOfClass:NSClassFromString(@"KSBaseWKWebViewController")] && ![viewController isKindOfClass:NSClassFromString(@"FirstSettingViewController")] && ![viewController isKindOfClass:NSClassFromString(@"TXLiveRoomViewController")] && ![viewController isKindOfClass:NSClassFromString(@"TXClassroomViewController")] && ![viewController isKindOfClass:NSClassFromString(@"KSAccompanyDraftViewController")] && ![viewController isKindOfClass:NSClassFromString(@"KSDraftMergeViewController")] && ![viewController isKindOfClass:NSClassFromString(@"CloudBaseViewController")]) {
  82. self.interactivePopGestureRecognizer.enabled = YES;
  83. }
  84. }
  85. - (void)didReceiveMemoryWarning {
  86. [super didReceiveMemoryWarning];
  87. // Dispose of any resources that can be recreated.
  88. }
  89. /*
  90. #pragma mark - Navigation
  91. // In a storyboard-based application, you will often want to do a little preparation before navigation
  92. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  93. // Get the new view controller using [segue destinationViewController].
  94. // Pass the selected object to the new view controller.
  95. }
  96. */
  97. @end