From fd35c5c9932ac43cc8103256359a3a94a3690ab0 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Fri, 21 Nov 2025 20:59:39 +0800 Subject: [PATCH] 1 --- CustomKeyboard/KeyboardViewController.m | 4 ++-- CustomKeyboard/View/KBKeyboardView.m | 8 ++++++-- keyBoard/AppDelegate.m | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index 584cb56..cd4d365 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -89,10 +89,10 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, CGFloat keyboardHeight = KEYBOARDHEIGHT; // 250 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; - + NSLayoutConstraint *h = [self.view.heightAnchor constraintEqualToConstant:keyboardHeight]; NSLayoutConstraint *w = [self.view.widthAnchor constraintEqualToConstant:screenWidth]; - + h.priority = UILayoutPriorityRequired; w.priority = UILayoutPriorityRequired; [NSLayoutConstraint activateConstraints:@[h, w]]; diff --git a/CustomKeyboard/View/KBKeyboardView.m b/CustomKeyboard/View/KBKeyboardView.m index e46b622..c402ecd 100644 --- a/CustomKeyboard/View/KBKeyboardView.m +++ b/CustomKeyboard/View/KBKeyboardView.m @@ -500,11 +500,15 @@ edgeSpacerMultiplier:(CGFloat)edgeSpacerMultiplier { }]; } - // 如果有左右占位,则把占位宽度设置为字符键宽度的一定倍数,以实现整体居中 + // 如果有左右占位,则把占位宽度设置为字符键宽度的一定倍数,以实现整体居中; + // 同时强约束左右占位宽度相等,避免在某些系统上由于布局冲突导致只压缩一侧, + // 出现“左侧有空隙,右侧无空隙”的情况。 if (leftSpacer && rightSpacer) { + // 1) 左右占位宽度必须相等 [leftSpacer mas_makeConstraints:^(MASConstraintMaker *make) { - make.width.equalTo(firstChar).multipliedBy(edgeSpacerMultiplier); + make.width.equalTo(rightSpacer); }]; + // 2) 同时都接近字符键宽度的 edgeSpacerMultiplier 倍数 [rightSpacer mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(firstChar).multipliedBy(edgeSpacerMultiplier); }]; diff --git a/keyBoard/AppDelegate.m b/keyBoard/AppDelegate.m index 5fe3c11..dba7ade 100644 --- a/keyBoard/AppDelegate.m +++ b/keyBoard/AppDelegate.m @@ -276,6 +276,18 @@ #pragma mark - Network check & alert - (void)kb_checkNetworkAndShowAlertIfNeeded { + // 首次安装且尚未完成首页引导时,不弹“无网络”提示,避免在系统蜂窝数据权限弹窗前就打扰用户 + static NSString *const kKBHasLaunchedOnce = @"KBHasLaunchedOnce"; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + if (![ud boolForKey:kKBHasLaunchedOnce]) { + return; + } + + // 仅在应用处于前台时提示 + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + return; + } + AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus; // 只有在“明确不可达”时才弹