添加键盘背景

This commit is contained in:
2025-11-04 21:01:46 +08:00
parent 3e2dc4bcb6
commit f43f94b94d
13 changed files with 528 additions and 15 deletions

View File

@@ -14,6 +14,7 @@
#import "Masonry.h"
#import "KBAuthManager.h"
#import "KBFullAccessManager.h"
#import "KBSkinManager.h"
static CGFloat KEYBOARDHEIGHT = 256 + 20;
@@ -22,6 +23,7 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20;
@property (nonatomic, strong) KBKeyBoardMainView *keyBoardMainView; // 0
@property (nonatomic, strong) KBFunctionView *functionView; // 0
@property (nonatomic, strong) KBSettingView *settingView; //
@property (nonatomic, strong) UIImageView *bgImageView; //
@end
@implementation KeyboardViewController
@@ -40,12 +42,23 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20;
__unused id token = [[NSNotificationCenter defaultCenter] addObserverForName:KBFullAccessChangedNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(__unused NSNotification * _Nonnull note) {
// 访 UI
}];
//
__unused id token2 = [[NSNotificationCenter defaultCenter] addObserverForName:KBSkinDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(__unused NSNotification * _Nonnull note) {
[self kb_applyTheme];
}];
[self kb_applyTheme];
}
- (void)setupUI {
//
[self.view.heightAnchor constraintEqualToConstant:KEYBOARDHEIGHT].active = YES;
//
[self.view addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
//
self.functionView.hidden = YES;
[self.view addSubview:self.functionView];
@@ -217,4 +230,40 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20;
__unused typeof(weakSelf) selfStrong = weakSelf;
}];
}
#pragma mark - Theme
- (void)kb_applyTheme {
KBSkinTheme *t = [KBSkinManager shared].current;
UIImage *img = [[KBSkinManager shared] currentBackgroundImage];
self.bgImageView.image = img;
BOOL hasImg = (img != nil);
self.view.backgroundColor = hasImg ? [UIColor clearColor] : t.keyboardBackground;
self.keyBoardMainView.backgroundColor = hasImg ? [UIColor clearColor] : t.keyboardBackground;
//
if ([self.keyBoardMainView respondsToSelector:@selector(kb_applyTheme)]) {
// method declared in KBKeyBoardMainView.h
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.keyBoardMainView performSelector:@selector(kb_applyTheme)];
#pragma clang diagnostic pop
}
if ([self.functionView respondsToSelector:@selector(kb_applyTheme)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.functionView performSelector:@selector(kb_applyTheme)];
#pragma clang diagnostic pop
}
}
#pragma mark - Lazy
- (UIImageView *)bgImageView {
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] init];
_bgImageView.contentMode = UIViewContentModeScaleAspectFill;
_bgImageView.clipsToBounds = YES;
}
return _bgImageView;
}
@end

View File

@@ -33,6 +33,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) UIButton *clearButton; // 右侧-清空
@property (nonatomic, strong, readonly) UIButton *sendButton; // 右侧-发送
/// 应用当前皮肤(更新背景/强调色)
- (void)kb_applyTheme;
@end
NS_ASSUME_NONNULL_END

View File

@@ -14,6 +14,7 @@
#import <MBProgressHUD.h>
#import "KBFullAccessGuideView.h"
#import "KBFullAccessManager.h"
#import "KBSkinManager.h"
static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
@@ -40,8 +41,8 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// 绿
self.backgroundColor = [UIColor colorWithRed:0.77 green:0.93 blue:0.82 alpha:1.0];
// 使
[self kb_applyTheme];
[self setupUI];
[self reloadDemoData];
@@ -52,6 +53,15 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
return self;
}
#pragma mark - Theme
- (void)kb_applyTheme {
KBSkinManager *mgr = [KBSkinManager shared];
UIColor *accent = mgr.current.accentColor ?: [UIColor colorWithRed:0.77 green:0.93 blue:0.82 alpha:1.0];
BOOL hasImg = ([mgr currentBackgroundImage] != nil);
self.backgroundColor = hasImg ? [accent colorWithAlphaComponent:0.65] : accent;
}
- (void)dealloc {
[self stopPasteboardMonitor];
}

View File

@@ -28,6 +28,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface KBKeyBoardMainView : UIView
@property (nonatomic, weak) id<KBKeyBoardMainViewDelegate> delegate;
/// 应用当前皮肤(会触发键区重载以应用按键颜色)
- (void)kb_applyTheme;
@end
NS_ASSUME_NONNULL_END

View File

@@ -11,6 +11,7 @@
#import "KBFunctionView.h"
#import "KBKey.h"
#import "Masonry.h"
#import "KBSkinManager.h"
@interface KBKeyBoardMainView ()<KBToolBarDelegate, KBKeyboardViewDelegate>
@property (nonatomic, strong) KBToolBar *topBar;
@@ -21,7 +22,7 @@
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
self.backgroundColor = [KBSkinManager shared].current.keyboardBackground;
//
self.topBar = [[KBToolBar alloc] init];
self.topBar.delegate = self;
@@ -31,7 +32,7 @@
make.top.equalTo(self.mas_top).offset(6);
make.height.mas_equalTo(40);
}];
//
self.keyboardView = [[KBKeyboardView alloc] init];
self.keyboardView.delegate = self;
@@ -41,9 +42,9 @@
make.top.equalTo(self.topBar.mas_bottom).offset(4);
make.bottom.equalTo(self.mas_bottom).offset(-4);
}];
// /
}
return self;
}
@@ -114,5 +115,15 @@
//
// KeyboardViewController
#pragma mark - Theme
- (void)kb_applyTheme {
KBSkinManager *mgr = [KBSkinManager shared];
BOOL hasImg = ([mgr currentBackgroundImage] != nil);
UIColor *bg = mgr.current.keyboardBackground;
self.backgroundColor = hasImg ? [UIColor clearColor] : bg;
self.keyboardView.backgroundColor = hasImg ? [UIColor clearColor] : bg;
[self.keyboardView reloadKeys];
}
@end

View File

@@ -5,6 +5,7 @@
#import "KBKeyButton.h"
#import "KBKey.h"
#import "KBSkinManager.h"
@implementation KBKeyButton
@@ -16,10 +17,11 @@
}
- (void)applyDefaultStyle {
self.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold]; //
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
self.backgroundColor = [UIColor whiteColor];
self.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
KBSkinTheme *t = [KBSkinManager shared].current;
[self setTitleColor:t.keyTextColor forState:UIControlStateNormal];
[self setTitleColor:t.keyTextColor forState:UIControlStateHighlighted];
self.backgroundColor = t.keyBackground;
self.layer.cornerRadius = 6.0; //
self.layer.masksToBounds = NO;
self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.1].CGColor; //
@@ -46,10 +48,11 @@
- (void)refreshStateAppearance {
// Shift/CapsLock
KBSkinTheme *t = [KBSkinManager shared].current;
if (self.isSelected) {
self.backgroundColor = [UIColor colorWithWhite:0.85 alpha:1.0];
self.backgroundColor = t.keyHighlightBackground ?: t.keyBackground;
} else {
self.backgroundColor = [UIColor whiteColor];
self.backgroundColor = t.keyBackground;
}
}

View File

@@ -7,6 +7,7 @@
#import "KBKeyButton.h"
#import "KBKey.h"
#import "KBResponderUtils.h" //
#import "KBSkinManager.h"
@interface KBKeyboardView ()
@property (nonatomic, strong) UIView *row1;
@@ -22,7 +23,7 @@
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
self.backgroundColor = [KBSkinManager shared].current.keyboardBackground;
_layoutStyle = KBKeyboardLayoutStyleLetters;
// Shift
_shiftOn = NO;