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