From 0031b7a5f6dd7acdee99a188db885b9c9893e262 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Tue, 28 Oct 2025 18:02:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/KeyboardViewController.m | 54 +++++++++++++++++ CustomKeyboard/Network/KBNetworkManager.m | 2 +- CustomKeyboard/View/KBKeyBoardMainView.h | 3 + CustomKeyboard/View/KBKeyBoardMainView.m | 7 ++- CustomKeyboard/View/KBSettingView.h | 20 +++++++ CustomKeyboard/View/KBSettingView.m | 71 +++++++++++++++++++++++ keyBoard.xcodeproj/project.pbxproj | 10 ++++ 7 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 CustomKeyboard/View/KBSettingView.h create mode 100644 CustomKeyboard/View/KBSettingView.m diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index d54ebf7..5b80484 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -10,6 +10,7 @@ #import "KBKey.h" #import "KBFunctionView.h" +#import "KBSettingView.h" #import "Masonry.h" static CGFloat KEYBOARDHEIGHT = 256 + 20; @@ -18,6 +19,7 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20; @property (nonatomic, strong) UIButton *nextKeyboardButton; // 系统“下一个键盘”按钮(可选) @property (nonatomic, strong) KBKeyBoardMainView *keyBoardMainView; // 功能面板视图(点击工具栏第0个时显示) @property (nonatomic, strong) KBFunctionView *functionView; // 功能面板视图(点击工具栏第0个时显示) +@property (nonatomic, strong) KBSettingView *settingView; // 设置页 @end @implementation KeyboardViewController @@ -67,6 +69,43 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20; } } +/// 显示/隐藏设置页(高度与 keyBoardMainView 一致),右侧滑入/滑出 +- (void)showSettingView:(BOOL)show { + if (show) { +// if (!self.settingView) { + self.settingView = [[KBSettingView alloc] init]; + self.settingView.hidden = YES; + [self.view addSubview:self.settingView]; + [self.settingView mas_makeConstraints:^(MASConstraintMaker *make) { + // 与键盘主视图完全等同的区域,保证高度、宽度一致 + make.edges.equalTo(self.keyBoardMainView); + }]; + [self.settingView.backButton addTarget:self action:@selector(onTapSettingsBack) forControlEvents:UIControlEventTouchUpInside]; +// } + [self.view bringSubviewToFront:self.settingView]; + // 以 keyBoardMainView 的实际宽度为准,避免首次添加时 self.view 宽度尚未计算 + [self.view layoutIfNeeded]; + CGFloat w = CGRectGetWidth(self.keyBoardMainView.bounds); + if (w <= 0) { w = CGRectGetWidth(self.view.bounds); } + if (w <= 0) { w = [UIScreen mainScreen].bounds.size.width; } + self.settingView.transform = CGAffineTransformMakeTranslation(w, 0); + self.settingView.hidden = NO; + [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ + self.settingView.transform = CGAffineTransformIdentity; + } completion:nil]; + } else { + if (!self.settingView || self.settingView.hidden) return; + CGFloat w = CGRectGetWidth(self.keyBoardMainView.bounds); + if (w <= 0) { w = CGRectGetWidth(self.view.bounds); } + if (w <= 0) { w = [UIScreen mainScreen].bounds.size.width; } + [UIView animateWithDuration:0.22 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ + self.settingView.transform = CGAffineTransformMakeTranslation(w, 0); + } completion:^(BOOL finished) { + self.settingView.hidden = YES; + }]; + } +} + // MARK: - KBKeyBoardMainViewDelegate @@ -99,6 +138,10 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20; } } +- (void)keyBoardMainViewDidTapSettings:(KBKeyBoardMainView *)keyBoardMainView { + [self showSettingView:YES]; +} + // MARK: - KBFunctionViewDelegate - (void)functionView:(KBFunctionView *)functionView didTapToolActionAtIndex:(NSInteger)index { // 需求:当 index == 0 时,切回键盘主视图 @@ -124,7 +167,18 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20; return _functionView; } +- (KBSettingView *)settingView { + if (!_settingView) { + _settingView = [[KBSettingView alloc] init]; + } + return _settingView; +} +#pragma mark - Actions + +- (void)onTapSettingsBack { + [self showSettingView:NO]; +} @end diff --git a/CustomKeyboard/Network/KBNetworkManager.m b/CustomKeyboard/Network/KBNetworkManager.m index b507b98..a1c415c 100644 --- a/CustomKeyboard/Network/KBNetworkManager.m +++ b/CustomKeyboard/Network/KBNetworkManager.m @@ -4,7 +4,7 @@ // #import "KBNetworkManager.h" -#import +#import "AFNetworking.h" NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; diff --git a/CustomKeyboard/View/KBKeyBoardMainView.h b/CustomKeyboard/View/KBKeyBoardMainView.h index c6a9305..9f50800 100644 --- a/CustomKeyboard/View/KBKeyBoardMainView.h +++ b/CustomKeyboard/View/KBKeyBoardMainView.h @@ -20,6 +20,9 @@ NS_ASSUME_NONNULL_BEGIN /// 顶部工具栏按钮点击回调(index: 0~3)。 /// 需求:当 index == 0 时,由外部(KeyboardViewController)决定是否切换到功能面板 - (void)keyBoardMainView:(KBKeyBoardMainView *)keyBoardMainView didTapToolActionAtIndex:(NSInteger)index; + +/// 点击了右侧设置按钮 +- (void)keyBoardMainViewDidTapSettings:(KBKeyBoardMainView *)keyBoardMainView; @end @interface KBKeyBoardMainView : UIView diff --git a/CustomKeyboard/View/KBKeyBoardMainView.m b/CustomKeyboard/View/KBKeyBoardMainView.m index db6fc25..fb41669 100644 --- a/CustomKeyboard/View/KBKeyBoardMainView.m +++ b/CustomKeyboard/View/KBKeyBoardMainView.m @@ -59,8 +59,9 @@ } - (void)toolBarDidTapSettings:(KBToolBar *)toolBar { - // 这里示例仅插入一个标记。 -// [self.textDocumentProxy insertText:@"[settings]"]; + if ([self.delegate respondsToSelector:@selector(keyBoardMainViewDidTapSettings:)]) { + [self.delegate keyBoardMainViewDidTapSettings:self]; + } } #pragma mark - KBKeyboardViewDelegate @@ -112,4 +113,6 @@ // 切换功能面板交由外部控制器处理(此处不再实现) +// 设置页展示改由 KeyboardViewController 统一处理 + @end diff --git a/CustomKeyboard/View/KBSettingView.h b/CustomKeyboard/View/KBSettingView.h new file mode 100644 index 0000000..a802f6a --- /dev/null +++ b/CustomKeyboard/View/KBSettingView.h @@ -0,0 +1,20 @@ +// +// KBSettingView.h +// CustomKeyboard +// +// 简单的设置页面:左上角返回箭头按钮 + 占位内容区域。 +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface KBSettingView : UIView + +/// 左上角返回按钮(外部添加 target 实现返回) +@property (nonatomic, strong, readonly) UIButton *backButton; + +@end + +NS_ASSUME_NONNULL_END + diff --git a/CustomKeyboard/View/KBSettingView.m b/CustomKeyboard/View/KBSettingView.m new file mode 100644 index 0000000..f8fa089 --- /dev/null +++ b/CustomKeyboard/View/KBSettingView.m @@ -0,0 +1,71 @@ +// +// KBSettingView.m +// CustomKeyboard +// + +#import "KBSettingView.h" +#import "Masonry.h" + +@interface KBSettingView () +@property (nonatomic, strong) UIButton *backButtonInternal; +@property (nonatomic, strong) UILabel *titleLabel; +@end + +@implementation KBSettingView + +- (instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + // 背景做成淡色,和主界面区分 + self.backgroundColor = [UIColor colorWithWhite:1 alpha:0.96]; + + [self addSubview:self.backButtonInternal]; + [self.backButtonInternal mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.mas_left).offset(10); + make.top.equalTo(self.mas_top).offset(8); + make.width.height.mas_equalTo(32); + }]; + + self.titleLabel = [[UILabel alloc] init]; + self.titleLabel.text = @"设置"; + self.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold]; + self.titleLabel.textColor = [UIColor blackColor]; + [self addSubview:self.titleLabel]; + [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerY.equalTo(self.backButtonInternal.mas_centerY); + make.centerX.equalTo(self.mas_centerX); + }]; + + // 占位内容 + UILabel *place = [[UILabel alloc] init]; + place.text = @"这里是设置内容占位"; + place.textColor = [UIColor darkGrayColor]; + place.font = [UIFont systemFontOfSize:14]; + [self addSubview:place]; + [place mas_makeConstraints:^(MASConstraintMaker *make) { + make.center.equalTo(self); + }]; + } + return self; +} + +#pragma mark - Lazy + +- (UIButton *)backButtonInternal { + if (!_backButtonInternal) { + _backButtonInternal = [UIButton buttonWithType:UIButtonTypeSystem]; + _backButtonInternal.layer.cornerRadius = 16; + _backButtonInternal.layer.masksToBounds = YES; + _backButtonInternal.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0]; + [_backButtonInternal setTitle:@"←" forState:UIControlStateNormal]; // 返回箭头 + [_backButtonInternal setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + _backButtonInternal.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold]; + } + return _backButtonInternal; +} + +#pragma mark - Expose + +- (UIButton *)backButton { return self.backButtonInternal; } + +@end + diff --git a/keyBoard.xcodeproj/project.pbxproj b/keyBoard.xcodeproj/project.pbxproj index c46c22d..bbfd922 100644 --- a/keyBoard.xcodeproj/project.pbxproj +++ b/keyBoard.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 04FC95732EB09570007BD342 /* KBFunctionBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95722EB09570007BD342 /* KBFunctionBarView.m */; }; 04FC95762EB095DE007BD342 /* KBFunctionPasteView.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95752EB095DE007BD342 /* KBFunctionPasteView.m */; }; 04FC95792EB09BC8007BD342 /* KBKeyBoardMainView.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95782EB09BC8007BD342 /* KBKeyBoardMainView.m */; }; + 04FC95B22EB0B2CC007BD342 /* KBSettingView.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95B12EB0B2CC007BD342 /* KBSettingView.m */; }; 7A36414DFDA5BEC9B7D2E318 /* Pods_CustomKeyboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C1092FB2B452F95B15D4263 /* Pods_CustomKeyboard.framework */; }; A1B2C3D42EB0A0A100000001 /* KBFunctionTagCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D32EB0A0A100000001 /* KBFunctionTagCell.m */; }; A1B2C3E22EB0C0A100000001 /* KBNetworkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3E12EB0C0A100000001 /* KBNetworkManager.m */; }; @@ -88,6 +89,8 @@ 04FC95752EB095DE007BD342 /* KBFunctionPasteView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBFunctionPasteView.m; sourceTree = ""; }; 04FC95772EB09BC8007BD342 /* KBKeyBoardMainView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBKeyBoardMainView.h; sourceTree = ""; }; 04FC95782EB09BC8007BD342 /* KBKeyBoardMainView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBKeyBoardMainView.m; sourceTree = ""; }; + 04FC95B02EB0B2CC007BD342 /* KBSettingView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBSettingView.h; sourceTree = ""; }; + 04FC95B12EB0B2CC007BD342 /* KBSettingView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBSettingView.m; sourceTree = ""; }; 2C1092FB2B452F95B15D4263 /* Pods_CustomKeyboard.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CustomKeyboard.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 51FE7C4C42C2255B3C1C4128 /* Pods-keyBoard.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-keyBoard.release.xcconfig"; path = "Target Support Files/Pods-keyBoard/Pods-keyBoard.release.xcconfig"; sourceTree = ""; }; 727EC7532EAF848B00B36487 /* keyBoard.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = keyBoard.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -172,6 +175,8 @@ 04FC95752EB095DE007BD342 /* KBFunctionPasteView.m */, A1B2C3D22EB0A0A100000001 /* KBFunctionTagCell.h */, A1B2C3D32EB0A0A100000001 /* KBFunctionTagCell.m */, + 04FC95B02EB0B2CC007BD342 /* KBSettingView.h */, + 04FC95B12EB0B2CC007BD342 /* KBSettingView.m */, ); path = View; sourceTree = ""; @@ -374,10 +379,14 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-keyBoard/Pods-keyBoard-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); + inputPaths = ( + ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-keyBoard/Pods-keyBoard-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); + outputPaths = ( + ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-keyBoard/Pods-keyBoard-frameworks.sh\"\n"; @@ -420,6 +429,7 @@ A1B2C3D42EB0A0A100000001 /* KBFunctionTagCell.m in Sources */, A1B2C3E22EB0C0A100000001 /* KBNetworkManager.m in Sources */, 04FC956A2EB05497007BD342 /* KBKeyButton.m in Sources */, + 04FC95B22EB0B2CC007BD342 /* KBSettingView.m in Sources */, 04FC95702EB09516007BD342 /* KBFunctionView.m in Sources */, 04FC956D2EB054B7007BD342 /* KBKeyboardView.m in Sources */, 04FC95672EB0546C007BD342 /* KBKey.m in Sources */,