数字面板#+=/123”切换

This commit is contained in:
2025-10-28 20:03:43 +08:00
parent 4c7fd9049f
commit 935284388c
3 changed files with 57 additions and 24 deletions

View File

@@ -16,7 +16,8 @@ typedef NS_ENUM(NSInteger, KBKeyType) {
KBKeyTypeSpace, // 空格 KBKeyTypeSpace, // 空格
KBKeyTypeReturn, // 回车/发送 KBKeyTypeReturn, // 回车/发送
KBKeyTypeGlobe, // 系统地球键 KBKeyTypeGlobe, // 系统地球键
KBKeyTypeCustom // 自定义功能占位 KBKeyTypeCustom, // 自定义功能占位
KBKeyTypeSymbolsToggle // 数字面板内的“#+=/123”切换
}; };
@interface KBKey : NSObject @interface KBKey : NSObject

View File

@@ -25,6 +25,8 @@ typedef NS_ENUM(NSInteger, KBKeyboardLayoutStyle) {
@property (nonatomic, weak) id<KBKeyboardViewDelegate> delegate; @property (nonatomic, weak) id<KBKeyboardViewDelegate> delegate;
@property (nonatomic, assign) KBKeyboardLayoutStyle layoutStyle; // 布局样式(字母/数字) @property (nonatomic, assign) KBKeyboardLayoutStyle layoutStyle; // 布局样式(字母/数字)
@property (nonatomic, assign, getter=isShiftOn) BOOL shiftOn; // 大小写状态 @property (nonatomic, assign, getter=isShiftOn) BOOL shiftOn; // 大小写状态
// 在数字布局中,是否显示“更多符号”(#+=)页
@property (nonatomic, assign) BOOL symbolsMoreOn;
- (void)reloadKeys; // 当布局样式/大小写变化时调用 - (void)reloadKeys; // 当布局样式/大小写变化时调用

View File

@@ -23,12 +23,21 @@
_layoutStyle = KBKeyboardLayoutStyleLetters; _layoutStyle = KBKeyboardLayoutStyleLetters;
// Shift // Shift
_shiftOn = NO; _shiftOn = NO;
_symbolsMoreOn = NO; // 123
[self buildBase]; [self buildBase];
[self reloadKeys]; [self reloadKeys];
} }
return self; return self;
} }
// /
- (void)setLayoutStyle:(KBKeyboardLayoutStyle)layoutStyle {
_layoutStyle = layoutStyle;
if (_layoutStyle != KBKeyboardLayoutStyleNumbers) {
_symbolsMoreOn = NO;
}
}
- (void)buildBase { - (void)buildBase {
[self addSubview:self.row1]; [self addSubview:self.row1];
[self addSubview:self.row2]; [self addSubview:self.row2];
@@ -77,29 +86,44 @@
- (NSArray<NSArray<KBKey *> *> *)buildKeysForCurrentLayout { - (NSArray<NSArray<KBKey *> *> *)buildKeysForCurrentLayout {
if (self.layoutStyle == KBKeyboardLayoutStyleNumbers) { if (self.layoutStyle == KBKeyboardLayoutStyleNumbers) {
// /3 + // /3 +
NSArray *r1 = @[ NSArray *r1 = nil;
[KBKey keyWithTitle:@"1" output:@"1"], [KBKey keyWithTitle:@"2" output:@"2"], [KBKey keyWithTitle:@"3" output:@"3"], NSArray *r2 = nil;
[KBKey keyWithTitle:@"4" output:@"4"], [KBKey keyWithTitle:@"5" output:@"5"], [KBKey keyWithTitle:@"6" output:@"6"], NSArray *r3 = nil;
[KBKey keyWithTitle:@"7" output:@"7"], [KBKey keyWithTitle:@"8" output:@"8"], [KBKey keyWithTitle:@"9" output:@"9"], [KBKey keyWithTitle:@"0" output:@"0"],
]; if (!self.symbolsMoreOn) {
NSArray *r2 = @[ // 123
[KBKey keyWithTitle:@"-" output:@"-"], [KBKey keyWithTitle:@"/" output:@"/"], [KBKey keyWithTitle:@":" output:@":"], r1 = @[ [KBKey keyWithTitle:@"1" output:@"1"], [KBKey keyWithTitle:@"2" output:@"2"], [KBKey keyWithTitle:@"3" output:@"3"],
[KBKey keyWithTitle:@";" output:@";"], [KBKey keyWithTitle:@"(" output:@"("], [KBKey keyWithTitle:@")" output:@")"], [KBKey keyWithTitle:@"4" output:@"4"], [KBKey keyWithTitle:@"5" output:@"5"], [KBKey keyWithTitle:@"6" output:@"6"],
[KBKey keyWithTitle:@"$" output:@"$"], [KBKey keyWithTitle:@"&" output:@"&"], [KBKey keyWithTitle:@"@" output:@"@"], [KBKey keyWithTitle:@"\"" output:@"\""], [KBKey keyWithTitle:@"7" output:@"7"], [KBKey keyWithTitle:@"8" output:@"8"], [KBKey keyWithTitle:@"9" output:@"9"], [KBKey keyWithTitle:@"0" output:@"0"] ];
]; r2 = @[ [KBKey keyWithTitle:@"-" output:@"-"], [KBKey keyWithTitle:@"/" output:@"/"], [KBKey keyWithTitle:@":" output:@":"],
NSArray *r3 = @[ [KBKey keyWithTitle:@";" output:@";"], [KBKey keyWithTitle:@"(" output:@"("], [KBKey keyWithTitle:@")" output:@")"],
[KBKey keyWithTitle:@"#+=" type:KBKeyTypeModeChange], [KBKey keyWithTitle:@"$" output:@"$"], [KBKey keyWithTitle:@"&" output:@"&"], [KBKey keyWithTitle:@"@" output:@"@"], [KBKey keyWithTitle:@"\"" output:@"\""] ];
[KBKey keyWithTitle:@"," output:@","], [KBKey keyWithTitle:@"." output:@"."], [KBKey keyWithTitle:@"?" output:@"?"], r3 = @[ [KBKey keyWithTitle:@"#+=" type:KBKeyTypeSymbolsToggle],
[KBKey keyWithTitle:@"!" output:@"!"], [KBKey keyWithTitle:@"'" output:@"'"], [KBKey keyWithTitle:@"," output:@","], [KBKey keyWithTitle:@"." output:@"."], [KBKey keyWithTitle:@"?" output:@"?"],
[KBKey keyWithTitle:@"" type:KBKeyTypeBackspace], [KBKey keyWithTitle:@"!" output:@"!"], [KBKey keyWithTitle:@"'" output:@"'"],
]; [KBKey keyWithTitle:@"⌫" type:KBKeyTypeBackspace] ];
NSArray *r4 = @[ } else {
[KBKey keyWithTitle:@"ABC" type:KBKeyTypeModeChange], // #+=123
[KBKey keyWithTitle:@"," output:@","], r1 = @[ [KBKey keyWithTitle:@"[" output:@"["], [KBKey keyWithTitle:@"]" output:@"]"], [KBKey keyWithTitle:@"{" output:@"{"],
[KBKey keyWithTitle:@"space" type:KBKeyTypeSpace], [KBKey keyWithTitle:@"}" output:@"}"], [KBKey keyWithTitle:@"#" output:@"#"], [KBKey keyWithTitle:@"%" output:@"%"],
[KBKey keyWithTitle:@"中/英" type:KBKeyTypeCustom], [KBKey keyWithTitle:@"^" output:@"^"], [KBKey keyWithTitle:@"*" output:@"*"], [KBKey keyWithTitle:@"+" output:@"+"],
[KBKey keyWithTitle:@"发送" type:KBKeyTypeReturn], [KBKey keyWithTitle:@"=" output:@"="] ];
]; r2 = @[ [KBKey keyWithTitle:@"_" output:@"_"], [KBKey keyWithTitle:@"\\" output:@"\\"], [KBKey keyWithTitle:@"|" output:@"|"],
[KBKey keyWithTitle:@"~" output:@"~"], [KBKey keyWithTitle:@"<" output:@"<"], [KBKey keyWithTitle:@">" output:@">"],
[KBKey keyWithTitle:@"$" output:@"$"], [KBKey keyWithTitle:@"€" output:@"€"], [KBKey keyWithTitle:@"£" output:@"£"],
[KBKey keyWithTitle:@"•" output:@"•"] ];
r3 = @[ [KBKey keyWithTitle:@"123" type:KBKeyTypeSymbolsToggle],
[KBKey keyWithTitle:@"," output:@","], [KBKey keyWithTitle:@"." output:@"."], [KBKey keyWithTitle:@"?" output:@"?"],
[KBKey keyWithTitle:@"!" output:@"!"], [KBKey keyWithTitle:@"'" output:@"'"],
[KBKey keyWithTitle:@"⌫" type:KBKeyTypeBackspace] ];
}
NSArray *r4 = @[ [KBKey keyWithTitle:@"ABC" type:KBKeyTypeModeChange],
[KBKey keyWithTitle:@"," output:@","],
[KBKey keyWithTitle:@"space" type:KBKeyTypeSpace],
[KBKey keyWithTitle:@"中/英" type:KBKeyTypeCustom],
[KBKey keyWithTitle:@"发送" type:KBKeyTypeReturn] ];
return @[r1, r2, r3, r4]; return @[r1, r2, r3, r4];
} }
@@ -251,6 +275,12 @@
[self reloadKeys]; [self reloadKeys];
return; return;
} }
if (key.type == KBKeyTypeSymbolsToggle) {
// 123 <-> #+=
self.symbolsMoreOn = !self.symbolsMoreOn;
[self reloadKeys];
return;
}
if ([self.delegate respondsToSelector:@selector(keyboardView:didTapKey:)]) { if ([self.delegate respondsToSelector:@selector(keyboardView:didTapKey:)]) {
[self.delegate keyboardView:self didTapKey:key]; [self.delegate keyboardView:self didTapKey:key];
} }