From bc623676caf4c01f48da4cce0be3dd82d82da574 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Tue, 24 Feb 2026 15:24:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E5=90=8E=EF=BC=8C=E9=94=AE=E7=9B=98=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E4=B8=8D=E5=AD=98=E5=9C=A8=EF=BC=8C=20=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E4=B9=9F=E4=B8=8D=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/View/KBKeyBoardMainView.m | 4 +++ CustomKeyboard/View/KBKeyboardView.m | 33 ++++++++++++++++++++++++ Shared/KBMaiPointReporter.m | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CustomKeyboard/View/KBKeyBoardMainView.m b/CustomKeyboard/View/KBKeyBoardMainView.m index b81be25..abea8d5 100644 --- a/CustomKeyboard/View/KBKeyBoardMainView.m +++ b/CustomKeyboard/View/KBKeyBoardMainView.m @@ -95,6 +95,10 @@ [self.keyboardView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.topBar.mas_bottom).offset(barSpacing); }]; + // 首次创建时立即生成按键,避免只出现 4 行容器但按键未渲染的情况。 + [self.keyboardView reloadKeys]; + // 同步应用一次主题,确保键盘背景与按键皮肤在首帧可见。 + [self kb_applyTheme]; // 功能面板切换交由外部控制器处理;此处不直接创建/管理 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kb_undoStateChanged) diff --git a/CustomKeyboard/View/KBKeyboardView.m b/CustomKeyboard/View/KBKeyboardView.m index 46a256b..65437b6 100644 --- a/CustomKeyboard/View/KBKeyboardView.m +++ b/CustomKeyboard/View/KBKeyboardView.m @@ -125,6 +125,39 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5; [self buildRow:self.row2 withRowConfig:rows[1]]; [self buildRow:self.row3 withRowConfig:rows[2]]; [self buildRow:self.row4 withRowConfig:rows[3]]; + + NSUInteger totalButtons = [self kb_totalKeyButtonCount]; + if (totalButtons == 0) { + NSLog(@"[KBKeyboardView] config layout produced no keys, fallback to legacy."); + for (UIView *row in @[self.row1, self.row2, self.row3, self.row4]) { + [row.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; + } + [self kb_buildLegacyLayout]; + } +} + +- (void)didMoveToWindow { + [super didMoveToWindow]; + if (!self.window) { return; } + if ([self kb_totalKeyButtonCount] > 0) { return; } + // 兜底:系统编辑菜单切出切回等场景下,若按键丢失则自动重建。 + [self reloadKeys]; + // 自动重建后再触发一次上层主题应用,避免“按键恢复了但皮肤背景没恢复”。 + UIView *container = self.superview; + if ([container respondsToSelector:@selector(kb_applyTheme)]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [container performSelector:@selector(kb_applyTheme)]; +#pragma clang diagnostic pop + } +} + +- (NSUInteger)kb_totalKeyButtonCount { + NSUInteger total = 0; + for (UIView *row in @[self.row1, self.row2, self.row3, self.row4]) { + total += [self kb_collectKeyButtonsInView:row].count; + } + return total; } #pragma mark - Hit Test diff --git a/Shared/KBMaiPointReporter.m b/Shared/KBMaiPointReporter.m index 366ab24..2f29c62 100644 --- a/Shared/KBMaiPointReporter.m +++ b/Shared/KBMaiPointReporter.m @@ -95,7 +95,7 @@ static void KBMaiPoint_DebugLogError(NSURLResponse *response, NSError *error) { @"eventId": trimmedName, @"value": val.copy }; -// [self postPath:KB_MAI_POINT_PATH_GENERIC_DATA parameters:params completion:completion]; + [self postPath:KB_MAI_POINT_PATH_GENERIC_DATA parameters:params completion:completion]; } - (void)reportPageExposureWithEventName:(NSString *)eventName