This commit is contained in:
2025-12-03 16:05:00 +08:00
parent 22e393e588
commit 04a392e7c7
10 changed files with 126 additions and 4 deletions

View File

@@ -41,4 +41,42 @@
[super pushViewController:viewController animated:animated];
}
/// Push VC class VC push
- (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;
}
}
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];
}
}
[self setViewControllers:stack animated:animated];
}
@end