From 8e93f8f86f0d92ee4f82a8ec014386ea37a8009b Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Fri, 21 Nov 2025 21:50:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=8C=96=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/KeyboardViewController.m | 16 +++++++++------- CustomKeyboard/View/KBKeyBoardMainView.m | 17 +++++++++-------- CustomKeyboard/View/KBKeyboardView.m | 8 ++++---- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index cd4d365..553aed6 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -23,7 +23,8 @@ - (void)kb_consumePendingShopSkin; @end -static CGFloat KEYBOARDHEIGHT = 200 + 50; +// 以 375 宽设计稿为基准的键盘总高度(包括顶部工具栏) +static const CGFloat kKBKeyboardDesignHeight = 250.0f; static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, void *observer, @@ -45,7 +46,6 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, @property (nonatomic, strong) KBFunctionView *functionView; // 功能面板视图(点击工具栏第0个时显示) @property (nonatomic, strong) KBSettingView *settingView; // 设置页 @property (nonatomic, strong) UIImageView *bgImageView; // 背景图(在底层) -- (void)kb_consumePendingShopSkin; @end @implementation KeyboardViewController @@ -87,8 +87,10 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, - (void)setupUI { self.view.translatesAutoresizingMaskIntoConstraints = NO; - CGFloat keyboardHeight = KEYBOARDHEIGHT; // 250 + // 按屏幕宽度对设计值做等比缩放,避免在不同机型上键盘整体高度失真导致皮肤被压缩/拉伸 + CGFloat keyboardHeight = KBFit(kKBKeyboardDesignHeight); CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; + CGFloat outerVerticalInset = KBFit(4.0f); NSLayoutConstraint *h = [self.view.heightAnchor constraintEqualToConstant:keyboardHeight]; NSLayoutConstraint *w = [self.view.widthAnchor constraintEqualToConstant:screenWidth]; @@ -113,15 +115,15 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, [self.view addSubview:self.functionView]; [self.functionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); - make.top.equalTo(self.view).offset(4); - make.bottom.equalTo(self.view.mas_bottom).offset(-4); + make.top.equalTo(self.view).offset(outerVerticalInset); + make.bottom.equalTo(self.view.mas_bottom).offset(-outerVerticalInset); }]; [self.view addSubview:self.keyBoardMainView]; [self.keyBoardMainView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); - make.top.equalTo(self.view).offset(4); - make.bottom.equalTo(self.view.mas_bottom).offset(-4); + make.top.equalTo(self.view).offset(outerVerticalInset); + make.bottom.equalTo(self.view.mas_bottom).offset(-outerVerticalInset); }]; } diff --git a/CustomKeyboard/View/KBKeyBoardMainView.m b/CustomKeyboard/View/KBKeyBoardMainView.m index 8281d5a..ecca872 100644 --- a/CustomKeyboard/View/KBKeyBoardMainView.m +++ b/CustomKeyboard/View/KBKeyBoardMainView.m @@ -29,23 +29,24 @@ self.topBar = [[KBToolBar alloc] init]; self.topBar.delegate = self; [self addSubview:self.topBar]; - // 键盘区域 + // 键盘区域(高度按照设计值做等比缩放,避免不同机型上按键被压缩/拉伸) + CGFloat keyboardAreaHeight = KBFit(200.0f); + CGFloat bottomInset = KBFit(4.0f); + CGFloat barSpacing = KBFit(6.0f); + self.keyboardView = [[KBKeyboardView alloc] init]; self.keyboardView.delegate = self; [self addSubview:self.keyboardView]; [self.keyboardView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self); -// make.top.equalTo(self.topBar.mas_bottom).offset(4); - make.height.mas_equalTo(200); - make.bottom.equalTo(self.mas_bottom).offset(-4); + make.height.mas_equalTo(keyboardAreaHeight); + make.bottom.equalTo(self.mas_bottom).offset(-bottomInset); }]; - - + [self.topBar mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self); make.top.equalTo(self.mas_top).offset(0); -// make.height.mas_equalTo(40); - make.bottom.equalTo(self.keyboardView.mas_top).offset(-6); + make.bottom.equalTo(self.keyboardView.mas_top).offset(-barSpacing); }]; // 功能面板切换交由外部控制器处理;此处不直接创建/管理 diff --git a/CustomKeyboard/View/KBKeyboardView.m b/CustomKeyboard/View/KBKeyboardView.m index c402ecd..2feb255 100644 --- a/CustomKeyboard/View/KBKeyboardView.m +++ b/CustomKeyboard/View/KBKeyboardView.m @@ -10,10 +10,10 @@ #import "KBSkinManager.h" #import "KBKeyPreviewView.h" -// UI 常量统一管理,方便后续调试样式 -static const CGFloat kKBRowVerticalSpacing = 8.0; -static const CGFloat kKBRowHorizontalInset = 6.0; -static const CGFloat kKBRowHeight = 40.0; +// UI 常量统一管理,方便后续调试样式(以 375 宽设计稿为基准,通过 KBFit 做等比缩放) +#define kKBRowVerticalSpacing KBFit(8.0f) +#define kKBRowHorizontalInset KBFit(6.0f) +#define kKBRowHeight KBFit(40.0f) static const NSTimeInterval kKBBackspaceLongPressMinDuration = 0.35; static const NSTimeInterval kKBBackspaceRepeatInterval = 0.06;