CustomNavViewController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 = HexRGB(0xf6f8f9);
  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:HexRGB(0xf6f8f9)];
  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. if (self.viewControllers.count > 1) {
  72. self.topViewController.hidesBottomBarWhenPushed = NO;
  73. }
  74. NSArray<__kindof UIViewController *> *viewControllers = [super popToRootViewControllerAnimated:animated];
  75. // self.viewControllers has two items here on iOS14
  76. return viewControllers;
  77. }
  78. #pragma mark - UINavigationControllerDelegate
  79. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  80. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)] && ![viewController isKindOfClass:NSClassFromString(@"KSBaseWKWebViewController")] && ![viewController isKindOfClass:NSClassFromString(@"FirstSettingViewController")] && ![viewController isKindOfClass:NSClassFromString(@"TXLiveRoomViewController")] && ![viewController isKindOfClass:NSClassFromString(@"TXClassroomViewController")]) {
  81. self.interactivePopGestureRecognizer.enabled = YES;
  82. }
  83. }
  84. - (void)didReceiveMemoryWarning {
  85. [super didReceiveMemoryWarning];
  86. // Dispose of any resources that can be recreated.
  87. }
  88. /*
  89. #pragma mark - Navigation
  90. // In a storyboard-based application, you will often want to do a little preparation before navigation
  91. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  92. // Get the new view controller using [segue destinationViewController].
  93. // Pass the selected object to the new view controller.
  94. }
  95. */
  96. @end