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

@@ -11,6 +11,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface BaseNavigationController : UINavigationController
/// Push 一个 VC如果栈中已存在同 class 的 VC则先移除旧的再 push 新的。
/// 常用于类似“登录/注册”这类会互相跳转的页面,避免堆叠多个相同页面实例。
- (void)kb_pushViewControllerRemovingSameClass:(UIViewController *)viewController
animated:(BOOL)animated;
@end
NS_ASSUME_NONNULL_END

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

View File

@@ -6,6 +6,7 @@
//
#import "KBEmailLoginVC.h"
#import "KBEmailRegistVC.h"
@interface KBEmailLoginVC () <UITextViewDelegate, UITextFieldDelegate>
@@ -225,6 +226,13 @@
- (void)onTapSignUp {
KBLOG(@"KBEmailLoginVC onTapSignUp");
KBEmailRegistVC *vc = [[KBEmailRegistVC alloc] init];
UINavigationController *nav = KB_CURRENT_NAV;
if ([nav isKindOfClass:[BaseNavigationController class]]) {
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
} else {
[nav pushViewController:vc animated:YES];
}
}
- (void)onTapTogglePassword:(UIButton *)sender {

View File

@@ -324,8 +324,12 @@
- (void)onTapEmailLogin {
KBLOG(@"onTapEmailLogin in KBEmailRegistVC");
KBEmailLoginVC *vc = [[KBEmailLoginVC alloc] init];
[KB_CURRENT_NAV pushViewController:vc animated:true];
UINavigationController *nav = KB_CURRENT_NAV;
if ([nav isKindOfClass:[BaseNavigationController class]]) {
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
} else {
[nav pushViewController:vc animated:YES];
}
}
#pragma mark - Agreement Tap

View File

@@ -0,0 +1,16 @@
//
// KBForgetPwdVC.h
// keyBoard
//
// Created by Mac on 2025/12/3.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface KBForgetPwdVC : UIViewController
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,31 @@
//
// KBForgetPwdVC.m
// keyBoard
//
// Created by Mac on 2025/12/3.
//
#import "KBForgetPwdVC.h"
@interface KBForgetPwdVC ()
@end
@implementation KBForgetPwdVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end

View File

@@ -190,7 +190,12 @@
//
KBLOG(@"onTapEmailLogin");
KBEmailLoginVC *vc = [[KBEmailLoginVC alloc] init];
[KB_CURRENT_NAV pushViewController:vc animated:true];
UINavigationController *nav = KB_CURRENT_NAV;
if ([nav isKindOfClass:[BaseNavigationController class]]) {
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
} else {
[nav pushViewController:vc animated:YES];
}
}
- (void)onTapPolicy {
@@ -202,7 +207,12 @@
//
KBLOG(@"onTapSignUp");
KBEmailRegistVC *vc = [[KBEmailRegistVC alloc] init];
[KB_CURRENT_NAV pushViewController:vc animated:true];
UINavigationController *nav = KB_CURRENT_NAV;
if ([nav isKindOfClass:[BaseNavigationController class]]) {
[(BaseNavigationController *)nav kb_pushViewControllerRemovingSameClass:vc animated:YES];
} else {
[nav pushViewController:vc animated:YES];
}
}
- (void)onTapForgotPassword {