添加设置

This commit is contained in:
2025-10-28 18:02:10 +08:00
parent 02dd204744
commit 0031b7a5f6
7 changed files with 164 additions and 3 deletions

View File

@@ -10,6 +10,7 @@
#import "KBKey.h"
#import "KBFunctionView.h"
#import "KBSettingView.h"
#import "Masonry.h"
static CGFloat KEYBOARDHEIGHT = 256 + 20;
@@ -18,6 +19,7 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20;
@property (nonatomic, strong) UIButton *nextKeyboardButton; //
@property (nonatomic, strong) KBKeyBoardMainView *keyBoardMainView; // 0
@property (nonatomic, strong) KBFunctionView *functionView; // 0
@property (nonatomic, strong) KBSettingView *settingView; //
@end
@implementation KeyboardViewController
@@ -67,6 +69,43 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20;
}
}
/// / keyBoardMainView /
- (void)showSettingView:(BOOL)show {
if (show) {
// if (!self.settingView) {
self.settingView = [[KBSettingView alloc] init];
self.settingView.hidden = YES;
[self.view addSubview:self.settingView];
[self.settingView mas_makeConstraints:^(MASConstraintMaker *make) {
//
make.edges.equalTo(self.keyBoardMainView);
}];
[self.settingView.backButton addTarget:self action:@selector(onTapSettingsBack) forControlEvents:UIControlEventTouchUpInside];
// }
[self.view bringSubviewToFront:self.settingView];
// keyBoardMainView self.view
[self.view layoutIfNeeded];
CGFloat w = CGRectGetWidth(self.keyBoardMainView.bounds);
if (w <= 0) { w = CGRectGetWidth(self.view.bounds); }
if (w <= 0) { w = [UIScreen mainScreen].bounds.size.width; }
self.settingView.transform = CGAffineTransformMakeTranslation(w, 0);
self.settingView.hidden = NO;
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.settingView.transform = CGAffineTransformIdentity;
} completion:nil];
} else {
if (!self.settingView || self.settingView.hidden) return;
CGFloat w = CGRectGetWidth(self.keyBoardMainView.bounds);
if (w <= 0) { w = CGRectGetWidth(self.view.bounds); }
if (w <= 0) { w = [UIScreen mainScreen].bounds.size.width; }
[UIView animateWithDuration:0.22 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.settingView.transform = CGAffineTransformMakeTranslation(w, 0);
} completion:^(BOOL finished) {
self.settingView.hidden = YES;
}];
}
}
// MARK: - KBKeyBoardMainViewDelegate
@@ -99,6 +138,10 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20;
}
}
- (void)keyBoardMainViewDidTapSettings:(KBKeyBoardMainView *)keyBoardMainView {
[self showSettingView:YES];
}
// MARK: - KBFunctionViewDelegate
- (void)functionView:(KBFunctionView *)functionView didTapToolActionAtIndex:(NSInteger)index {
// index == 0
@@ -124,7 +167,18 @@ static CGFloat KEYBOARDHEIGHT = 256 + 20;
return _functionView;
}
- (KBSettingView *)settingView {
if (!_settingView) {
_settingView = [[KBSettingView alloc] init];
}
return _settingView;
}
#pragma mark - Actions
- (void)onTapSettingsBack {
[self showSettingView:NO];
}
@end

View File

@@ -4,7 +4,7 @@
//
#import "KBNetworkManager.h"
#import <AFNetworking/AFNetworking.h>
#import "AFNetworking.h"
NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";

View File

@@ -20,6 +20,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 顶部工具栏按钮点击回调index: 0~3
/// 需求:当 index == 0 时由外部KeyboardViewController决定是否切换到功能面板
- (void)keyBoardMainView:(KBKeyBoardMainView *)keyBoardMainView didTapToolActionAtIndex:(NSInteger)index;
/// 点击了右侧设置按钮
- (void)keyBoardMainViewDidTapSettings:(KBKeyBoardMainView *)keyBoardMainView;
@end
@interface KBKeyBoardMainView : UIView

View File

@@ -59,8 +59,9 @@
}
- (void)toolBarDidTapSettings:(KBToolBar *)toolBar {
//
// [self.textDocumentProxy insertText:@"[settings]"];
if ([self.delegate respondsToSelector:@selector(keyBoardMainViewDidTapSettings:)]) {
[self.delegate keyBoardMainViewDidTapSettings:self];
}
}
#pragma mark - KBKeyboardViewDelegate
@@ -112,4 +113,6 @@
//
// KeyboardViewController
@end

View File

@@ -0,0 +1,20 @@
//
// KBSettingView.h
// CustomKeyboard
//
// 简单的设置页面:左上角返回箭头按钮 + 占位内容区域。
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface KBSettingView : UIView
/// 左上角返回按钮(外部添加 target 实现返回)
@property (nonatomic, strong, readonly) UIButton *backButton;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,71 @@
//
// KBSettingView.m
// CustomKeyboard
//
#import "KBSettingView.h"
#import "Masonry.h"
@interface KBSettingView ()
@property (nonatomic, strong) UIButton *backButtonInternal;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation KBSettingView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//
self.backgroundColor = [UIColor colorWithWhite:1 alpha:0.96];
[self addSubview:self.backButtonInternal];
[self.backButtonInternal mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(10);
make.top.equalTo(self.mas_top).offset(8);
make.width.height.mas_equalTo(32);
}];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.text = @"设置";
self.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
self.titleLabel.textColor = [UIColor blackColor];
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.backButtonInternal.mas_centerY);
make.centerX.equalTo(self.mas_centerX);
}];
//
UILabel *place = [[UILabel alloc] init];
place.text = @"这里是设置内容占位";
place.textColor = [UIColor darkGrayColor];
place.font = [UIFont systemFontOfSize:14];
[self addSubview:place];
[place mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
}];
}
return self;
}
#pragma mark - Lazy
- (UIButton *)backButtonInternal {
if (!_backButtonInternal) {
_backButtonInternal = [UIButton buttonWithType:UIButtonTypeSystem];
_backButtonInternal.layer.cornerRadius = 16;
_backButtonInternal.layer.masksToBounds = YES;
_backButtonInternal.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
[_backButtonInternal setTitle:@"←" forState:UIControlStateNormal]; //
[_backButtonInternal setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
_backButtonInternal.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
}
return _backButtonInternal;
}
#pragma mark - Expose
- (UIButton *)backButton { return self.backButtonInternal; }
@end