Files
keyboard/keyBoard/Class/Base/VC/BaseNavigationController.m

111 lines
3.5 KiB
Mathematica
Raw Normal View History

2025-10-29 14:17:26 +08:00
//
// BaseNavigationController.m
// keyBoard
//
// Created by Mac on 2025/10/29.
//
#import "BaseNavigationController.h"
2025-12-18 14:57:28 +08:00
@interface BaseNavigationController () <UIGestureRecognizerDelegate>
2025-10-29 14:17:26 +08:00
@end
@implementation BaseNavigationController
- (void)viewDidLoad {
2026-01-19 19:14:20 +08:00
[super viewDidLoad];
//
UIImage *backImg = [UIImage imageNamed:@"back_black_icon"];
if (backImg) {
self.navigationBar.backIndicatorImage = backImg;
self.navigationBar.backIndicatorTransitionMaskImage = backImg;
}
self.navigationBar.tintColor = [UIColor blackColor]; // /
if (@available(iOS 14.0, *)) {
self.navigationBar.topItem.backButtonDisplayMode =
UINavigationItemBackButtonDisplayModeMinimal;
}
// interactivePopGestureRecognizer
// /
if (self.interactivePopGestureRecognizer) {
self.interactivePopGestureRecognizer.delegate = self;
self.interactivePopGestureRecognizer.enabled = YES;
}
2025-10-29 14:17:26 +08:00
}
2026-01-19 19:14:20 +08:00
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if (self.viewControllers.count > 0) {
viewController.hidesBottomBarWhenPushed = true;
UIViewController *prev = self.topViewController;
if (@available(iOS 14.0, *)) {
prev.navigationItem.backButtonDisplayMode =
UINavigationItemBackButtonDisplayModeMinimal;
} else {
prev.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@""
style:UIBarButtonItemStylePlain
target:nil
action:nil];
2025-10-29 14:17:26 +08:00
}
2026-01-19 19:14:20 +08:00
}
[super pushViewController:viewController animated:animated];
2025-10-29 14:17:26 +08:00
}
2025-12-18 14:57:28 +08:00
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
2026-01-19 19:14:20 +08:00
if (gestureRecognizer == self.interactivePopGestureRecognizer) {
return self.viewControllers.count > 1;
}
return YES;
2025-12-18 14:57:28 +08:00
}
2025-12-03 16:05:00 +08:00
/// Push VC class VC push
2026-01-19 19:14:20 +08:00
- (void)kb_pushViewControllerRemovingSameClass:
(UIViewController *)viewController
animated:(BOOL)animated {
if (!viewController) {
return;
}
NSMutableArray<UIViewController *> *stack = self.viewControllers.mutableCopy;
// class VC
UIViewController *toRemove = nil;
for (UIViewController *vc in stack) {
if ([vc isKindOfClass:[viewController class]]) {
toRemove = vc;
break;
2025-12-03 16:05:00 +08:00
}
2026-01-19 19:14:20 +08:00
}
if (toRemove) {
[stack removeObject:toRemove];
}
// VC
[stack addObject:viewController];
// VC pushViewController:
if (stack.count > 1) {
viewController.hidesBottomBarWhenPushed = YES;
UIViewController *prev = stack[stack.count - 2];
if (@available(iOS 14.0, *)) {
prev.navigationItem.backButtonDisplayMode =
UINavigationItemBackButtonDisplayModeMinimal;
} else {
prev.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@""
style:UIBarButtonItemStylePlain
target:nil
action:nil];
2025-12-03 16:05:00 +08:00
}
2026-01-19 19:14:20 +08:00
}
2025-12-03 16:05:00 +08:00
2026-01-19 19:14:20 +08:00
[self setViewControllers:stack animated:animated];
2025-12-03 16:05:00 +08:00
}
2025-10-29 14:17:26 +08:00
@end