diff --git a/CustomKeyboard/Model/KBKey.h b/CustomKeyboard/Model/KBKey.h index 3a8c1ed..44bcdda 100644 --- a/CustomKeyboard/Model/KBKey.h +++ b/CustomKeyboard/Model/KBKey.h @@ -16,7 +16,8 @@ typedef NS_ENUM(NSInteger, KBKeyType) { KBKeyTypeSpace, // 空格 KBKeyTypeReturn, // 回车/发送 KBKeyTypeGlobe, // 系统地球键 - KBKeyTypeCustom // 自定义功能占位 + KBKeyTypeCustom, // 自定义功能占位 + KBKeyTypeSymbolsToggle // 数字面板内的“#+=/123”切换 }; @interface KBKey : NSObject diff --git a/CustomKeyboard/View/KBKeyboardView.h b/CustomKeyboard/View/KBKeyboardView.h index d81b3dc..e3487ac 100644 --- a/CustomKeyboard/View/KBKeyboardView.h +++ b/CustomKeyboard/View/KBKeyboardView.h @@ -25,6 +25,8 @@ typedef NS_ENUM(NSInteger, KBKeyboardLayoutStyle) { @property (nonatomic, weak) id delegate; @property (nonatomic, assign) KBKeyboardLayoutStyle layoutStyle; // 布局样式(字母/数字) @property (nonatomic, assign, getter=isShiftOn) BOOL shiftOn; // 大小写状态 +// 在数字布局中,是否显示“更多符号”(#+=)页 +@property (nonatomic, assign) BOOL symbolsMoreOn; - (void)reloadKeys; // 当布局样式/大小写变化时调用 diff --git a/CustomKeyboard/View/KBKeyboardView.m b/CustomKeyboard/View/KBKeyboardView.m index 622d270..f822001 100644 --- a/CustomKeyboard/View/KBKeyboardView.m +++ b/CustomKeyboard/View/KBKeyboardView.m @@ -23,12 +23,21 @@ _layoutStyle = KBKeyboardLayoutStyleLetters; // 默认小写:与需求一致,初始不开启 Shift _shiftOn = NO; + _symbolsMoreOn = NO; // 数字面板默认第一页(123) [self buildBase]; [self reloadKeys]; } return self; } +// 当切换大布局(字母/数字)时,重置数字二级页状态 +- (void)setLayoutStyle:(KBKeyboardLayoutStyle)layoutStyle { + _layoutStyle = layoutStyle; + if (_layoutStyle != KBKeyboardLayoutStyleNumbers) { + _symbolsMoreOn = NO; + } +} + - (void)buildBase { [self addSubview:self.row1]; [self addSubview:self.row2]; @@ -77,29 +86,44 @@ - (NSArray *> *)buildKeysForCurrentLayout { if (self.layoutStyle == KBKeyboardLayoutStyleNumbers) { // 数字/符号布局:3 行主键 + 底部控制行 - NSArray *r1 = @[ - [KBKey keyWithTitle:@"1" output:@"1"], [KBKey keyWithTitle:@"2" output:@"2"], [KBKey keyWithTitle:@"3" output:@"3"], - [KBKey keyWithTitle:@"4" output:@"4"], [KBKey keyWithTitle:@"5" output:@"5"], [KBKey keyWithTitle:@"6" output:@"6"], - [KBKey keyWithTitle:@"7" output:@"7"], [KBKey keyWithTitle:@"8" output:@"8"], [KBKey keyWithTitle:@"9" output:@"9"], [KBKey keyWithTitle:@"0" output:@"0"], - ]; - NSArray *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:@"\""], - ]; - NSArray *r3 = @[ - [KBKey keyWithTitle:@"#+=" type:KBKeyTypeModeChange], - [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], - ]; + NSArray *r1 = nil; + NSArray *r2 = nil; + NSArray *r3 = nil; + + if (!self.symbolsMoreOn) { + // 数字第一页(123) + r1 = @[ [KBKey keyWithTitle:@"1" output:@"1"], [KBKey keyWithTitle:@"2" output:@"2"], [KBKey keyWithTitle:@"3" output:@"3"], + [KBKey keyWithTitle:@"4" output:@"4"], [KBKey keyWithTitle:@"5" output:@"5"], [KBKey keyWithTitle:@"6" output:@"6"], + [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:@":"], + [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] ]; + } else { + // 数字第二页(#+=):前两行替换为更多符号,左下角按钮文案改为“123” + r1 = @[ [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:@"="] ]; + 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]; } @@ -251,6 +275,12 @@ [self reloadKeys]; return; } + if (key.type == KBKeyTypeSymbolsToggle) { + // 在数字布局内切换 123 <-> #+= + self.symbolsMoreOn = !self.symbolsMoreOn; + [self reloadKeys]; + return; + } if ([self.delegate respondsToSelector:@selector(keyboardView:didTapKey:)]) { [self.delegate keyboardView:self didTapKey:key]; }