2
This commit is contained in:
@@ -729,6 +729,20 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
|
||||
- (void)kb_applyTheme {
|
||||
KBSkinTheme *t = [KBSkinManager shared].current;
|
||||
UIImage *img = [[KBSkinManager shared] currentBackgroundImage];
|
||||
if ([self kb_isDefaultKeyboardTheme:t]) {
|
||||
CGSize size = self.bgImageView.bounds.size;
|
||||
if (size.width <= 0 || size.height <= 0) {
|
||||
[self.view layoutIfNeeded];
|
||||
size = self.bgImageView.bounds.size;
|
||||
}
|
||||
if (size.width <= 0 || size.height <= 0) {
|
||||
size = self.view.bounds.size;
|
||||
}
|
||||
if (size.width <= 0 || size.height <= 0) {
|
||||
size = [UIScreen mainScreen].bounds.size;
|
||||
}
|
||||
img = [self kb_defaultGradientImageWithSize:size];
|
||||
}
|
||||
NSLog(@"⌨️[Keyboard] apply theme id=%@ hasBg=%d", t.skinId, (img != nil));
|
||||
[self kb_logSkinDiagnosticsWithTheme:t backgroundImage:img];
|
||||
self.bgImageView.image = img;
|
||||
@@ -752,6 +766,32 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)kb_isDefaultKeyboardTheme:(KBSkinTheme *)theme {
|
||||
NSString *skinId = theme.skinId ?: @"";
|
||||
if (skinId.length == 0 || [skinId isEqualToString:@"default"]) {
|
||||
return YES;
|
||||
}
|
||||
return [skinId isEqualToString:kKBDefaultSkinId];
|
||||
}
|
||||
|
||||
- (UIImage *)kb_defaultGradientImageWithSize:(CGSize)size {
|
||||
if (size.width <= 0 || size.height <= 0) { return nil; }
|
||||
CAGradientLayer *layer = [CAGradientLayer layer];
|
||||
layer.frame = CGRectMake(0, 0, size.width, size.height);
|
||||
layer.startPoint = CGPointMake(0.5, 0.0);
|
||||
layer.endPoint = CGPointMake(0.5, 1.0);
|
||||
layer.colors = @[
|
||||
(id)[UIColor colorWithHex:0xDEDFE4].CGColor,
|
||||
(id)[UIColor colorWithHex:0xD1D3DB].CGColor
|
||||
];
|
||||
|
||||
UIGraphicsBeginImageContextWithOptions(size, YES, 0);
|
||||
[layer renderInContext:UIGraphicsGetCurrentContext()];
|
||||
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
return image;
|
||||
}
|
||||
|
||||
- (void)kb_logSkinDiagnosticsWithTheme:(KBSkinTheme *)theme
|
||||
backgroundImage:(UIImage *)image {
|
||||
#if DEBUG
|
||||
|
||||
Binary file not shown.
@@ -128,6 +128,46 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5;
|
||||
[self buildRow:self.row4 withRowConfig:rows[3]];
|
||||
}
|
||||
|
||||
#pragma mark - Hit Test
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
|
||||
UIView *hit = [super hitTest:point withEvent:event];
|
||||
if ([hit isKindOfClass:[KBKeyButton class]]) {
|
||||
return hit;
|
||||
}
|
||||
if (hit == self || hit == self.row1 || hit == self.row2 || hit == self.row3 || hit == self.row4) {
|
||||
KBKeyButton *btn = [self kb_nearestKeyButtonForPoint:point];
|
||||
if (btn) { return btn; }
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
|
||||
- (KBKeyButton *)kb_nearestKeyButtonForPoint:(CGPoint)point {
|
||||
// 扩大按键的可点击区域,优先响应间隙点击(贴近系统键盘手感)。
|
||||
CGFloat slopX = KBFit(8.0f);
|
||||
CGFloat slopY = KBFit(4.0f);
|
||||
KBKeyButton *best = nil;
|
||||
CGFloat bestDistance = CGFLOAT_MAX;
|
||||
NSArray<UIView *> *rows = @[self.row1, self.row2, self.row3, self.row4];
|
||||
for (UIView *row in rows) {
|
||||
for (UIView *view in row.subviews) {
|
||||
if (![view isKindOfClass:[KBKeyButton class]]) { continue; }
|
||||
KBKeyButton *btn = (KBKeyButton *)view;
|
||||
CGRect frame = [self convertRect:btn.frame fromView:row];
|
||||
CGRect hitFrame = CGRectInset(frame, -slopX, -slopY);
|
||||
if (!CGRectContainsPoint(hitFrame, point)) { continue; }
|
||||
CGFloat dx = point.x - CGRectGetMidX(frame);
|
||||
CGFloat dy = point.y - CGRectGetMidY(frame);
|
||||
CGFloat dist = (dx * dx) + (dy * dy);
|
||||
if (dist < bestDistance) {
|
||||
bestDistance = dist;
|
||||
best = btn;
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
#pragma mark - Key Model Construction
|
||||
|
||||
// 创建当前布局下各行的 KBKey 列表
|
||||
|
||||
Reference in New Issue
Block a user