This commit is contained in:
2025-10-28 10:18:10 +08:00
parent efb04d134e
commit 1deca2ae5b
166 changed files with 17288 additions and 1427 deletions

View File

@@ -6,11 +6,16 @@
//
#import "KeyboardViewController.h"
#import "KBToolBar.h"
#import "KBKeyboardView.h"
#import "KBKey.h"
static CGFloat KEYBOARDHEIGHT = 256;
@interface KeyboardViewController ()
@property (nonatomic, strong) UIButton *nextKeyboardButton;
@interface KeyboardViewController () <KBToolBarDelegate, KBKeyboardViewDelegate>
@property (nonatomic, strong) UIButton *nextKeyboardButton; //
@property (nonatomic, strong) KBToolBar *topBar;
@property (nonatomic, strong) KBKeyboardView *keyboardView;
@end
@implementation KeyboardViewController
@@ -18,7 +23,7 @@ static CGFloat KEYBOARDHEIGHT = 256;
- (void)updateViewConstraints {
[super updateViewConstraints];
// Add custom view sizing constraints here
//
}
- (void)viewDidLoad {
@@ -43,14 +48,29 @@ static CGFloat KEYBOARDHEIGHT = 256;
- (void)setupUI {
CGFloat toolBarHeight = 40;
CGFloat bottom = 5;
CGFloat buttonSpace = 8;
CGFloat eachButtonHeight = (KEYBOARDHEIGHT - toolBarHeight - 10 - 8 * 3 - bottom) / 4;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view];
// self.view.translatesAutoresizingMaskIntoConstraints = NO;
//
[self.view.heightAnchor constraintEqualToConstant:KEYBOARDHEIGHT].active = YES;
//
self.topBar = [[KBToolBar alloc] init];
self.topBar.delegate = self;
[self.view addSubview:self.topBar];
[self.topBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view.mas_top).offset(6);
make.height.mas_equalTo(40);
}];
//
self.keyboardView = [[KBKeyboardView alloc] init];
self.keyboardView.delegate = self;
[self.view addSubview:self.keyboardView];
[self.keyboardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.topBar.mas_bottom).offset(4);
make.bottom.equalTo(self.view.mas_bottom).offset(-4);
}];
}
@@ -61,11 +81,11 @@ static CGFloat KEYBOARDHEIGHT = 256;
}
- (void)textWillChange:(id<UITextInput>)textInput {
// The app is about to change the document's contents. Perform any preparation here.
//
}
- (void)textDidChange:(id<UITextInput>)textInput {
// The app has just changed the document's contents, the document context has been updated.
//
UIColor *textColor = nil;
if (self.textDocumentProxy.keyboardAppearance == UIKeyboardAppearanceDark) {
@@ -76,4 +96,46 @@ static CGFloat KEYBOARDHEIGHT = 256;
[self.nextKeyboardButton setTitleColor:textColor forState:UIControlStateNormal];
}
#pragma mark - KBToolBarDelegate
- (void)toolBar:(KBToolBar *)toolBar didTapActionAtIndex:(NSInteger)index {
// [A1]..[A4]
NSString *placeholder = [NSString stringWithFormat:@"[A%ld]", (long)index+1];
[self.textDocumentProxy insertText:placeholder];
}
- (void)toolBarDidTapSettings:(KBToolBar *)toolBar {
// openURL 宿
//
[self.textDocumentProxy insertText:@"[settings]"];
}
#pragma mark - KBKeyboardViewDelegate
- (void)keyboardView:(KBKeyboardView *)keyboard didTapKey:(KBKey *)key {
switch (key.type) {
case KBKeyTypeCharacter:
[self.textDocumentProxy insertText:key.output ?: key.title ?: @""]; break;
case KBKeyTypeBackspace:
[self.textDocumentProxy deleteBackward]; break;
case KBKeyTypeSpace:
[self.textDocumentProxy insertText:@" "]; break;
case KBKeyTypeReturn:
[self.textDocumentProxy insertText:@"\n"]; break;
case KBKeyTypeModeChange: {
// <->
keyboard.layoutStyle = (keyboard.layoutStyle == KBKeyboardLayoutStyleLetters) ? KBKeyboardLayoutStyleNumbers : KBKeyboardLayoutStyleLetters;
[keyboard reloadKeys];
} break;
case KBKeyTypeGlobe:
[self advanceToNextInputMode]; break;
case KBKeyTypeCustom:
//
[self.textDocumentProxy insertText:@"[lang]"]; break;
case KBKeyTypeShift:
// Shift KBKeyboardView
break;
}
}
@end