From 1f4556453958b2a46c1b4bbdb2e64ff26f26099c Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 6 Nov 2025 16:05:28 +0800 Subject: [PATCH] 5 --- keyBoard.xcodeproj/project.pbxproj | 36 ++- keyBoard/Class/Base/VC/BaseTabBarController.m | 6 +- keyBoard/Class/Home/V/KBPanModalView.h | 19 ++ keyBoard/Class/Home/V/KBPanModalView.m | 267 ++++++++++++++++++ keyBoard/Class/Home/VC/HomeHotVC.m | 4 + keyBoard/Class/Home/VC/HomeMainVC.h | 16 ++ keyBoard/Class/Home/VC/HomeMainVC.m | 58 ++++ keyBoard/Class/Home/VC/HomeRankVC.m | 1 + keyBoard/Class/Home/VC/HomeSheetVC.m | 1 + keyBoard/Class/Home/VC/HomeVC.m | 2 +- 10 files changed, 395 insertions(+), 15 deletions(-) create mode 100644 keyBoard/Class/Home/V/KBPanModalView.h create mode 100644 keyBoard/Class/Home/V/KBPanModalView.m create mode 100644 keyBoard/Class/Home/VC/HomeMainVC.h create mode 100644 keyBoard/Class/Home/VC/HomeMainVC.m diff --git a/keyBoard.xcodeproj/project.pbxproj b/keyBoard.xcodeproj/project.pbxproj index cd059c7..50a4752 100644 --- a/keyBoard.xcodeproj/project.pbxproj +++ b/keyBoard.xcodeproj/project.pbxproj @@ -14,12 +14,12 @@ 0477BD952EBAFF4E0055D639 /* KBURLOpenBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BD932EBAFF4E0055D639 /* KBURLOpenBridge.m */; }; 0477BDF02EBB76E30055D639 /* HomeSheetVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDEF2EBB76E30055D639 /* HomeSheetVC.m */; }; 0477BDF32EBB7B850055D639 /* KBDirectionIndicatorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDF22EBB7B850055D639 /* KBDirectionIndicatorView.m */; }; - A1B2E1012EBC7AAA00000001 /* KBTopThreeView.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2E0022EBC7AAA00000001 /* KBTopThreeView.m */; }; - A1B2E1022EBC7AAA00000001 /* HomeHotCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2E0042EBC7AAA00000001 /* HomeHotCell.m */; }; 0477BDF72EBC63A80055D639 /* KBTestVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDF62EBC63A80055D639 /* KBTestVC.m */; }; 0477BDFA2EBC66340055D639 /* HomeHeadView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDF92EBC66340055D639 /* HomeHeadView.m */; }; 0477BDFD2EBC6A170055D639 /* HomeHotVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDFC2EBC6A170055D639 /* HomeHotVC.m */; }; 0477BE002EBC6A330055D639 /* HomeRankVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDFF2EBC6A330055D639 /* HomeRankVC.m */; }; + 0477BE042EBC83130055D639 /* HomeMainVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BE032EBC83130055D639 /* HomeMainVC.m */; }; + 047C650D2EBC8A840035E841 /* KBPanModalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C650C2EBC8A840035E841 /* KBPanModalView.m */; }; 04A9FE0F2EB481100020DB6D /* KBHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC97082EB31B14007BD342 /* KBHUD.m */; }; 04A9FE132EB4D0D20020DB6D /* KBFullAccessManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A9FE112EB4D0D20020DB6D /* KBFullAccessManager.m */; }; 04A9FE162EB873C80020DB6D /* UIViewController+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A9FE152EB873C80020DB6D /* UIViewController+Extension.m */; }; @@ -71,6 +71,8 @@ A1B2C4202EB4B7A100000001 /* KBKeyboardPermissionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C4222EB4B7A100000001 /* KBKeyboardPermissionManager.m */; }; A1B2C4212EB4B7A100000001 /* KBKeyboardPermissionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C4222EB4B7A100000001 /* KBKeyboardPermissionManager.m */; }; A1B2D7022EB8C00100000001 /* KBLangTestVC.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2D7012EB8C00100000001 /* KBLangTestVC.m */; }; + A1B2E1012EBC7AAA00000001 /* KBTopThreeView.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2E0022EBC7AAA00000001 /* KBTopThreeView.m */; }; + A1B2E1022EBC7AAA00000001 /* HomeHotCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2E0042EBC7AAA00000001 /* HomeHotCell.m */; }; ECC9EE02174D86E8D792472F /* Pods_keyBoard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 967065BB5230E43F293B3AF9 /* Pods_keyBoard.framework */; }; /* End PBXBuildFile section */ @@ -109,10 +111,6 @@ 0477BDEF2EBB76E30055D639 /* HomeSheetVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeSheetVC.m; sourceTree = ""; }; 0477BDF12EBB7B850055D639 /* KBDirectionIndicatorView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBDirectionIndicatorView.h; sourceTree = ""; }; 0477BDF22EBB7B850055D639 /* KBDirectionIndicatorView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBDirectionIndicatorView.m; sourceTree = ""; }; - A1B2E0012EBC7AAA00000001 /* KBTopThreeView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBTopThreeView.h; sourceTree = ""; }; - A1B2E0022EBC7AAA00000001 /* KBTopThreeView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBTopThreeView.m; sourceTree = ""; }; - A1B2E0032EBC7AAA00000001 /* HomeHotCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeHotCell.h; sourceTree = ""; }; - A1B2E0042EBC7AAA00000001 /* HomeHotCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeHotCell.m; sourceTree = ""; }; 0477BDF52EBC63A80055D639 /* KBTestVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBTestVC.h; sourceTree = ""; }; 0477BDF62EBC63A80055D639 /* KBTestVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBTestVC.m; sourceTree = ""; }; 0477BDF82EBC66340055D639 /* HomeHeadView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeHeadView.h; sourceTree = ""; }; @@ -121,6 +119,10 @@ 0477BDFC2EBC6A170055D639 /* HomeHotVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeHotVC.m; sourceTree = ""; }; 0477BDFE2EBC6A330055D639 /* HomeRankVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeRankVC.h; sourceTree = ""; }; 0477BDFF2EBC6A330055D639 /* HomeRankVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeRankVC.m; sourceTree = ""; }; + 0477BE022EBC83130055D639 /* HomeMainVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeMainVC.h; sourceTree = ""; }; + 0477BE032EBC83130055D639 /* HomeMainVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeMainVC.m; sourceTree = ""; }; + 047C650B2EBC8A840035E841 /* KBPanModalView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBPanModalView.h; sourceTree = ""; }; + 047C650C2EBC8A840035E841 /* KBPanModalView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBPanModalView.m; sourceTree = ""; }; 04A9A67D2EB9E1690023B8F4 /* KBResponderUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBResponderUtils.h; sourceTree = ""; }; 04A9FE102EB4D0D20020DB6D /* KBFullAccessManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBFullAccessManager.h; sourceTree = ""; }; 04A9FE112EB4D0D20020DB6D /* KBFullAccessManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBFullAccessManager.m; sourceTree = ""; }; @@ -219,6 +221,10 @@ A1B2C4232EB4B7A100000001 /* KBKeyboardPermissionManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBKeyboardPermissionManager.h; sourceTree = ""; }; A1B2D7002EB8C00100000001 /* KBLangTestVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBLangTestVC.h; sourceTree = ""; }; A1B2D7012EB8C00100000001 /* KBLangTestVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBLangTestVC.m; sourceTree = ""; }; + A1B2E0012EBC7AAA00000001 /* KBTopThreeView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBTopThreeView.h; sourceTree = ""; }; + A1B2E0022EBC7AAA00000001 /* KBTopThreeView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBTopThreeView.m; sourceTree = ""; }; + A1B2E0032EBC7AAA00000001 /* HomeHotCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeHotCell.h; sourceTree = ""; }; + A1B2E0042EBC7AAA00000001 /* HomeHotCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeHotCell.m; sourceTree = ""; }; B12EC429812407B9F0E67565 /* Pods-CustomKeyboard.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CustomKeyboard.release.xcconfig"; path = "Target Support Files/Pods-CustomKeyboard/Pods-CustomKeyboard.release.xcconfig"; sourceTree = ""; }; B8CA018AB878499327504AAD /* Pods-CustomKeyboard.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CustomKeyboard.debug.xcconfig"; path = "Target Support Files/Pods-CustomKeyboard/Pods-CustomKeyboard.debug.xcconfig"; sourceTree = ""; }; F67DDBD716E4E616D8CC2C9C /* Pods-keyBoard.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-keyBoard.debug.xcconfig"; path = "Target Support Files/Pods-keyBoard/Pods-keyBoard.debug.xcconfig"; sourceTree = ""; }; @@ -379,10 +385,12 @@ 0477BDF22EBB7B850055D639 /* KBDirectionIndicatorView.m */, 0477BDF82EBC66340055D639 /* HomeHeadView.h */, 0477BDF92EBC66340055D639 /* HomeHeadView.m */, - A1B2E0012EBC7AAA00000001 /* KBTopThreeView.h */, - A1B2E0022EBC7AAA00000001 /* KBTopThreeView.m */, - A1B2E0032EBC7AAA00000001 /* HomeHotCell.h */, - A1B2E0042EBC7AAA00000001 /* HomeHotCell.m */, + A1B2E0012EBC7AAA00000001 /* KBTopThreeView.h */, + A1B2E0022EBC7AAA00000001 /* KBTopThreeView.m */, + A1B2E0032EBC7AAA00000001 /* HomeHotCell.h */, + A1B2E0042EBC7AAA00000001 /* HomeHotCell.m */, + 047C650B2EBC8A840035E841 /* KBPanModalView.h */, + 047C650C2EBC8A840035E841 /* KBPanModalView.m */, ); path = V; sourceTree = ""; @@ -392,6 +400,8 @@ children = ( 04FC95CD2EB1E7A1007BD342 /* HomeVC.h */, 04FC95CE2EB1E7A1007BD342 /* HomeVC.m */, + 0477BE022EBC83130055D639 /* HomeMainVC.h */, + 0477BE032EBC83130055D639 /* HomeMainVC.m */, 0477BDEE2EBB76E30055D639 /* HomeSheetVC.h */, 0477BDEF2EBB76E30055D639 /* HomeSheetVC.m */, 0477BDFB2EBC6A170055D639 /* HomeHotVC.h */, @@ -914,6 +924,7 @@ 04FC95E92EB23B67007BD342 /* KBNetworkManager.m in Sources */, 04FC95D22EB1E7AE007BD342 /* MyVC.m in Sources */, 0477BE002EBC6A330055D639 /* HomeRankVC.m in Sources */, + 047C650D2EBC8A840035E841 /* KBPanModalView.m in Sources */, 043FBCD22EAF97630036AFE1 /* KBPermissionViewController.m in Sources */, 04A9FE162EB873C80020DB6D /* UIViewController+Extension.m in Sources */, 04C6EABE2EAF86530089C901 /* AppDelegate.m in Sources */, @@ -939,9 +950,10 @@ A1B2D7022EB8C00100000001 /* KBLangTestVC.m in Sources */, 04C6EABF2EAF86530089C901 /* main.m in Sources */, 04FC95CC2EB1E780007BD342 /* BaseTabBarController.m in Sources */, + 0477BE042EBC83130055D639 /* HomeMainVC.m in Sources */, 0477BDFD2EBC6A170055D639 /* HomeHotVC.m in Sources */, - A1B2E1012EBC7AAA00000001 /* KBTopThreeView.m in Sources */, - A1B2E1022EBC7AAA00000001 /* HomeHotCell.m in Sources */, + A1B2E1012EBC7AAA00000001 /* KBTopThreeView.m in Sources */, + A1B2E1022EBC7AAA00000001 /* HomeHotCell.m in Sources */, 0459D1B72EBA287900F2D189 /* KBSkinManager.m in Sources */, 04FC95F42EB339C1007BD342 /* AppleSignInManager.m in Sources */, 04C6EAC12EAF86530089C901 /* ViewController.m in Sources */, diff --git a/keyBoard/Class/Base/VC/BaseTabBarController.m b/keyBoard/Class/Base/VC/BaseTabBarController.m index 68bd70b..b5a0105 100644 --- a/keyBoard/Class/Base/VC/BaseTabBarController.m +++ b/keyBoard/Class/Base/VC/BaseTabBarController.m @@ -7,6 +7,7 @@ #import "BaseTabBarController.h" #import "HomeVC.h" +#import "HomeMainVC.h" #import "MyVC.h" #import "BaseNavigationController.h" #import "KBAuthManager.h" @@ -19,7 +20,7 @@ - (void)viewDidLoad { [super viewDidLoad]; // Setup two tabs: Home & My, each embedded in BaseNavigationController - HomeVC *home = [[HomeVC alloc] init]; + HomeMainVC *home = [[HomeMainVC alloc] init]; home.title = @"首页"; BaseNavigationController *navHome = [[BaseNavigationController alloc] initWithRootViewController:home]; navHome.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:nil selectedImage:nil]; @@ -31,7 +32,8 @@ self.viewControllers = @[navHome, navMy]; - [[KBAuthManager shared] saveAccessToken:@"TEST" refreshToken:nil expiryDate:[NSDate dateWithTimeIntervalSinceNow:3600] userIdentifier:nil]; + // 测试储存Token + /*[[KBAuthManager shared] saveAccessToken:@"TEST" refreshToken:nil expiryDate:[NSDate dateWithTimeIntervalSinceNow:3600] userIdentifier:nil]*/; } /* diff --git a/keyBoard/Class/Home/V/KBPanModalView.h b/keyBoard/Class/Home/V/KBPanModalView.h new file mode 100644 index 0000000..e902fce --- /dev/null +++ b/keyBoard/Class/Home/V/KBPanModalView.h @@ -0,0 +1,19 @@ +// +// KBPanModalView.h +// keyBoard +// +// Created by Mac on 2025/11/6. +// + +#import +#import + +#import "HWPanModalContentView.h" +NS_ASSUME_NONNULL_BEGIN + +@interface KBPanModalView : HWPanModalContentView +@property (nonatomic, assign) CGFloat minHeight; // 例如 150 +@property (nonatomic, assign) CGFloat topInset; // 例如 100 +@end + +NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/Home/V/KBPanModalView.m b/keyBoard/Class/Home/V/KBPanModalView.m new file mode 100644 index 0000000..5fe71e9 --- /dev/null +++ b/keyBoard/Class/Home/V/KBPanModalView.m @@ -0,0 +1,267 @@ +// +// KBPanModalView.m +// keyBoard +// +// Created by Mac on 2025/11/6. +// + +#import "KBPanModalView.h" +#import "KBDirectionIndicatorView.h" +// 子控制器 +#import "HomeHotVC.h" +#import "HomeRankVC.h" +@interface KBPanModalView() +@property (nonatomic, strong) KBDirectionIndicatorView *indicator; +// 顶部切换按钮与指示条 +@property (nonatomic, strong) UIView *topBar; +@property (nonatomic, strong) UIButton *hotButton; +@property (nonatomic, strong) UIButton *rankButton; +@property (nonatomic, strong) UIView *underlineView; // 选中下划线 + +// 承载子控制器内容 +@property (nonatomic, strong) UIView *containerView; +@property (nonatomic, strong) UIViewController *currentChild; +@property (nonatomic, strong) HomeHotVC *hotVC; +@property (nonatomic, strong) HomeRankVC *rankVC; +@end +@implementation KBPanModalView + +- (instancetype)initWithFrame:(CGRect)frame{ + if (self = [super initWithFrame:frame]) { + self.backgroundColor = [UIColor redColor]; + HWBackgroundConfig *config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault]; + config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault]; + config.backgroundAlpha = 0.01; + [self.hw_dimmedView reloadConfig:config]; + // 顶部按钮 + 容器 + [self setupTopButtonsAndContainer]; + // 默认展示“热门” + [self switchToIndex:0 animated:NO]; + } + return self; +} + +- (UIView *)customIndicatorView { + if (!_indicator) _indicator = [KBDirectionIndicatorView new]; + return _indicator; +} + +//- (void)panModalTransitionDidFinish { +// // 初次展示后按当前状态设定一次朝向 +// [self.indicator applyPresentationState:self.hw_presentationState]; +// // 避免出现内容随弹窗上移的“位移动画”观感: +// // 顶部栏在展示动画期间先隐藏,待完成后淡入 +// if (self.topBar && self.topBar.alpha < 1.0) { +// [UIView animateWithDuration:0.18 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ +// self.topBar.alpha = 1.0; +// } completion:nil]; +// } +//} + +- (void)didChangeTransitionToState:(PresentationState)state { +// // 每次状态切换完成后刷新朝向 +// [self.indicator applyPresentationState:state]; +} + +- (PanModalHeight)shortFormHeight { + return PanModalHeightMake(PanModalHeightTypeContent, self.minHeight ?: 300); +} + +- (PanModalHeight)longFormHeight { + return PanModalHeightMake(PanModalHeightTypeMaxTopInset, self.topInset ?: 100); +} + +- (PresentationState)originPresentationState { + return PresentationStateShort; // 初始就以最小高度展示 +} + +- (BOOL)anchorModalToLongForm { + return YES; // 到 long 后不再继续往上拖 +} + +- (BOOL)allowsPullDownWhenShortState { + return NO; // 在 short 状态禁止继续往下拉(锁住最小高度) +} + +/// 允许时间穿透 +- (BOOL)allowsTouchEventsPassingThroughTransitionView { + return YES; +} + +-(BOOL)shouldAutoSetPanScrollContentInset{ + return NO; +} + + +- (UIScrollView *)panScrollable { + return self.hotVC.tableView; +} + +// 可选:完全不允许拖拽关闭(避免被拉到底消失) +- (BOOL)allowsDragToDismiss { + return NO; +} +// +//- (BOOL)showDragIndicator{ +// return NO; +//} +// +// 点背景不关闭 +- (BOOL)allowsTapBackgroundToDismiss { + return NO; +} + +// 出现时不做上推动画(瞬时到位)开了下拉动画有问题 +//- (NSTimeInterval)transitionDuration { +// return 0; +//} + +//// 可选:关闭触觉反馈,避免出现时的轻微震动 +//- (BOOL)isHapticFeedbackEnabled { +// return NO; +//} + + +#pragma mark - UI + +- (void)setupTopButtonsAndContainer { + // 顶部栏 + self.topBar = [[UIView alloc] init]; + self.topBar.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9]; + [self addSubview:self.topBar]; + // 首次展示时先隐藏,待转场完成后再淡入,避免“自底向上滑入”的错觉 + self.topBar.alpha = 0.0; + + // 两个按钮 + self.hotButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [self.hotButton setTitle:@"热门" forState:UIControlStateNormal]; + [self.hotButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal]; + [self.hotButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected]; + self.hotButton.titleLabel.font = [UIFont boldSystemFontOfSize:16]; + self.hotButton.tag = 0; + [self.hotButton addTarget:self action:@selector(onTapTopButton:) forControlEvents:UIControlEventTouchUpInside]; + [self.topBar addSubview:self.hotButton]; + + self.rankButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [self.rankButton setTitle:@"排行" forState:UIControlStateNormal]; + [self.rankButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal]; + [self.rankButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected]; + self.rankButton.titleLabel.font = [UIFont boldSystemFontOfSize:16]; + self.rankButton.tag = 1; + [self.rankButton addTarget:self action:@selector(onTapTopButton:) forControlEvents:UIControlEventTouchUpInside]; + [self.topBar addSubview:self.rankButton]; + + // 下划线(跟随选中按钮) + self.underlineView = [[UIView alloc] init]; + self.underlineView.backgroundColor = [UIColor blackColor]; + self.underlineView.layer.cornerRadius = 1.0; + [self.topBar addSubview:self.underlineView]; + + // 容器视图 + self.containerView = [[UIView alloc] init]; + self.containerView.backgroundColor = [UIColor whiteColor]; + self.containerView.clipsToBounds = YES; + [self addSubview:self.containerView]; + + // Masonry 约束 + CGFloat topPadding = 12; // 与顶部小指示器留点空间 + [self.topBar mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.right.equalTo(self); + make.top.equalTo(self).offset(topPadding); + make.height.mas_equalTo(44); + }]; + + [self.hotButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.bottom.equalTo(self.topBar); + make.left.equalTo(self.topBar); + }]; + [self.rankButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.bottom.equalTo(self.topBar); + make.right.equalTo(self.topBar); + make.left.equalTo(self.hotButton.mas_right); + make.width.equalTo(self.hotButton); + }]; + + // 初始先放在“热门”下方,宽度稍小于按钮文字 + [self.underlineView mas_makeConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(2); + make.bottom.equalTo(self.topBar.mas_bottom).offset(-2); + make.centerX.equalTo(self.hotButton); + make.width.mas_equalTo(24); + }]; + + [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.topBar.mas_bottom).offset(8); + make.left.right.bottom.equalTo(self); + }]; +} + +#pragma mark - Action + +- (void)onTapTopButton:(UIButton *)sender { + [self switchToIndex:sender.tag animated:YES]; + [self hw_panModalSetNeedsLayoutUpdate]; +} + +#pragma mark - Switch Child + +- (void)switchToIndex:(NSInteger)index animated:(BOOL)animated { + UIViewController *target = (index == 0) ? self.hotVC : self.rankVC; + if (!target) { + if (index == 0) { + self.hotVC = [HomeHotVC new]; + target = self.hotVC; + } else { + self.rankVC = [HomeRankVC new]; + target = self.rankVC; + } + } + + if (self.currentChild == target) { + // 已经是目标 + [self updateButtonStateForIndex:index animated:animated]; + return; + } + + // 移除当前 + if (self.currentChild) { + [self.currentChild willMoveToParentViewController:nil]; + [self.currentChild.view removeFromSuperview]; + [self.currentChild removeFromParentViewController]; + } + + // 添加目标 +// [self addChildViewController:target]; + [self.containerView addSubview:target.view]; + target.view.backgroundColor = [UIColor colorWithWhite:0.98 alpha:1]; + [target.view mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.containerView); + }]; + [target didMoveToParentViewController:self]; + self.currentChild = target; + + [self updateButtonStateForIndex:index animated:animated]; +} + +- (void)updateButtonStateForIndex:(NSInteger)index animated:(BOOL)animated { + self.hotButton.selected = (index == 0); + self.rankButton.selected = (index == 1); + + UIButton *btn = (index == 0) ? self.hotButton : self.rankButton; + // 更新下划线位置 + [self.underlineView mas_remakeConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(2); + make.bottom.equalTo(self.topBar.mas_bottom).offset(-2); + make.centerX.equalTo(btn); + make.width.mas_equalTo(24); + }]; + + if (animated) { + [UIView animateWithDuration:0.25 animations:^{ + [self.topBar layoutIfNeeded]; + }]; + } else { + [self.topBar layoutIfNeeded]; + } +} +@end diff --git a/keyBoard/Class/Home/VC/HomeHotVC.m b/keyBoard/Class/Home/VC/HomeHotVC.m index ef62dc0..602e7b0 100644 --- a/keyBoard/Class/Home/VC/HomeHotVC.m +++ b/keyBoard/Class/Home/VC/HomeHotVC.m @@ -9,6 +9,8 @@ // 视图 #import "KBTopThreeView.h" #import "HomeHotCell.h" +#import "HomeRankVC.h" + #import @interface HomeHotVC () @@ -80,6 +82,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; + HomeRankVC *vc = [[HomeRankVC alloc] init]; + [self.navigationController pushViewController:vc animated:true]; } #pragma mark - Lazy diff --git a/keyBoard/Class/Home/VC/HomeMainVC.h b/keyBoard/Class/Home/VC/HomeMainVC.h new file mode 100644 index 0000000..fb78ed1 --- /dev/null +++ b/keyBoard/Class/Home/VC/HomeMainVC.h @@ -0,0 +1,16 @@ +// +// HomeMainVC.h +// keyBoard +// +// Created by Mac on 2025/11/6. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface HomeMainVC : UIViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/Home/VC/HomeMainVC.m b/keyBoard/Class/Home/VC/HomeMainVC.m new file mode 100644 index 0000000..ccacb9a --- /dev/null +++ b/keyBoard/Class/Home/VC/HomeMainVC.m @@ -0,0 +1,58 @@ +// +// HomeMainVC.m +// keyBoard +// +// Created by Mac on 2025/11/6. +// + +#import "HomeMainVC.h" +#import "HomeHeadView.h" +#import "KBPanModalView.h" + +@interface HomeMainVC () +@property (nonatomic, strong) HomeHeadView *headView; + +@end + +@implementation HomeMainVC + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor yellowColor]; + CGFloat topV = (500); + +// [self.view addSubview:self.headView]; +// [self setupMas:topV]; + // 创建sheetVC + KBPanModalView *simplePanModalView = [[KBPanModalView alloc] init]; + // 使用宏,避免误写成函数指针判断导致恒为 true + if (KB_DEVICE_HAS_NOTCH) { + simplePanModalView.minHeight = KB_SCREEN_HEIGHT - topV - 34; + }else{ + simplePanModalView.minHeight = KB_SCREEN_HEIGHT - topV; +// + } + simplePanModalView.topInset = 100; + [simplePanModalView presentInView:self.view]; +} + +- (void)setupMas:(CGFloat)headViewTopV{ + [self.headView mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.right.equalTo(self.view); + make.top.equalTo(self.view); + make.height.mas_equalTo(headViewTopV); + }]; +} + + +#pragma mark - lazy +- (HomeHeadView *)headView{ + if (!_headView) { + _headView = [[HomeHeadView alloc] init]; + } + return _headView; +} + + +@end diff --git a/keyBoard/Class/Home/VC/HomeRankVC.m b/keyBoard/Class/Home/VC/HomeRankVC.m index 802a286..bd13aa3 100644 --- a/keyBoard/Class/Home/VC/HomeRankVC.m +++ b/keyBoard/Class/Home/VC/HomeRankVC.m @@ -16,6 +16,7 @@ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. + self.view.backgroundColor = [UIColor grayColor]; } /* diff --git a/keyBoard/Class/Home/VC/HomeSheetVC.m b/keyBoard/Class/Home/VC/HomeSheetVC.m index 19a9bb5..61a36e0 100644 --- a/keyBoard/Class/Home/VC/HomeSheetVC.m +++ b/keyBoard/Class/Home/VC/HomeSheetVC.m @@ -203,6 +203,7 @@ - (void)onTapTopButton:(UIButton *)sender { [self switchToIndex:sender.tag animated:YES]; + [self hw_panModalSetNeedsLayoutUpdate]; } #pragma mark - Switch Child diff --git a/keyBoard/Class/Home/VC/HomeVC.m b/keyBoard/Class/Home/VC/HomeVC.m index c51503d..94f4f45 100644 --- a/keyBoard/Class/Home/VC/HomeVC.m +++ b/keyBoard/Class/Home/VC/HomeVC.m @@ -30,7 +30,7 @@ vc.minHeight = KB_SCREEN_HEIGHT - topV - 34; }else{ vc.minHeight = KB_SCREEN_HEIGHT - topV; - +// } vc.topInset = 100; [self presentPanModal:vc];