动态化高度比例

This commit is contained in:
2025-11-21 21:50:40 +08:00
parent fd35c5c993
commit 8e93f8f86f
3 changed files with 22 additions and 19 deletions

View File

@@ -23,7 +23,8 @@
- (void)kb_consumePendingShopSkin; - (void)kb_consumePendingShopSkin;
@end @end
static CGFloat KEYBOARDHEIGHT = 200 + 50; // 375 稿
static const CGFloat kKBKeyboardDesignHeight = 250.0f;
static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
void *observer, void *observer,
@@ -45,7 +46,6 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
@property (nonatomic, strong) KBFunctionView *functionView; // 0 @property (nonatomic, strong) KBFunctionView *functionView; // 0
@property (nonatomic, strong) KBSettingView *settingView; // @property (nonatomic, strong) KBSettingView *settingView; //
@property (nonatomic, strong) UIImageView *bgImageView; // @property (nonatomic, strong) UIImageView *bgImageView; //
- (void)kb_consumePendingShopSkin;
@end @end
@implementation KeyboardViewController @implementation KeyboardViewController
@@ -87,8 +87,10 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
- (void)setupUI { - (void)setupUI {
self.view.translatesAutoresizingMaskIntoConstraints = NO; self.view.translatesAutoresizingMaskIntoConstraints = NO;
CGFloat keyboardHeight = KEYBOARDHEIGHT; // 250 // /
CGFloat keyboardHeight = KBFit(kKBKeyboardDesignHeight);
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat outerVerticalInset = KBFit(4.0f);
NSLayoutConstraint *h = [self.view.heightAnchor constraintEqualToConstant:keyboardHeight]; NSLayoutConstraint *h = [self.view.heightAnchor constraintEqualToConstant:keyboardHeight];
NSLayoutConstraint *w = [self.view.widthAnchor constraintEqualToConstant:screenWidth]; NSLayoutConstraint *w = [self.view.widthAnchor constraintEqualToConstant:screenWidth];
@@ -113,15 +115,15 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
[self.view addSubview:self.functionView]; [self.view addSubview:self.functionView];
[self.functionView mas_makeConstraints:^(MASConstraintMaker *make) { [self.functionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view); make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(4); make.top.equalTo(self.view).offset(outerVerticalInset);
make.bottom.equalTo(self.view.mas_bottom).offset(-4); make.bottom.equalTo(self.view.mas_bottom).offset(-outerVerticalInset);
}]; }];
[self.view addSubview:self.keyBoardMainView]; [self.view addSubview:self.keyBoardMainView];
[self.keyBoardMainView mas_makeConstraints:^(MASConstraintMaker *make) { [self.keyBoardMainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view); make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(4); make.top.equalTo(self.view).offset(outerVerticalInset);
make.bottom.equalTo(self.view.mas_bottom).offset(-4); make.bottom.equalTo(self.view.mas_bottom).offset(-outerVerticalInset);
}]; }];
} }

View File

@@ -29,23 +29,24 @@
self.topBar = [[KBToolBar alloc] init]; self.topBar = [[KBToolBar alloc] init];
self.topBar.delegate = self; self.topBar.delegate = self;
[self addSubview:self.topBar]; [self addSubview:self.topBar];
// // /
CGFloat keyboardAreaHeight = KBFit(200.0f);
CGFloat bottomInset = KBFit(4.0f);
CGFloat barSpacing = KBFit(6.0f);
self.keyboardView = [[KBKeyboardView alloc] init]; self.keyboardView = [[KBKeyboardView alloc] init];
self.keyboardView.delegate = self; self.keyboardView.delegate = self;
[self addSubview:self.keyboardView]; [self addSubview:self.keyboardView];
[self.keyboardView mas_makeConstraints:^(MASConstraintMaker *make) { [self.keyboardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self); make.left.right.equalTo(self);
// make.top.equalTo(self.topBar.mas_bottom).offset(4); make.height.mas_equalTo(keyboardAreaHeight);
make.height.mas_equalTo(200); make.bottom.equalTo(self.mas_bottom).offset(-bottomInset);
make.bottom.equalTo(self.mas_bottom).offset(-4);
}]; }];
[self.topBar mas_makeConstraints:^(MASConstraintMaker *make) { [self.topBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self); make.left.right.equalTo(self);
make.top.equalTo(self.mas_top).offset(0); make.top.equalTo(self.mas_top).offset(0);
// make.height.mas_equalTo(40); make.bottom.equalTo(self.keyboardView.mas_top).offset(-barSpacing);
make.bottom.equalTo(self.keyboardView.mas_top).offset(-6);
}]; }];
// / // /

View File

@@ -10,10 +10,10 @@
#import "KBSkinManager.h" #import "KBSkinManager.h"
#import "KBKeyPreviewView.h" #import "KBKeyPreviewView.h"
// UI 便 // UI 便 375 稿 KBFit
static const CGFloat kKBRowVerticalSpacing = 8.0; #define kKBRowVerticalSpacing KBFit(8.0f)
static const CGFloat kKBRowHorizontalInset = 6.0; #define kKBRowHorizontalInset KBFit(6.0f)
static const CGFloat kKBRowHeight = 40.0; #define kKBRowHeight KBFit(40.0f)
static const NSTimeInterval kKBBackspaceLongPressMinDuration = 0.35; static const NSTimeInterval kKBBackspaceLongPressMinDuration = 0.35;
static const NSTimeInterval kKBBackspaceRepeatInterval = 0.06; static const NSTimeInterval kKBBackspaceRepeatInterval = 0.06;