在非刘海添加地球

This commit is contained in:
2025-11-05 20:11:10 +08:00
parent 7a1b17d060
commit efdcf60ed1
2 changed files with 135 additions and 2 deletions

View File

@@ -7,12 +7,14 @@
#import "KBFunctionBarView.h" #import "KBFunctionBarView.h"
#import "Masonry.h" #import "Masonry.h"
#import "KBResponderUtils.h" // UIInputViewController
@interface KBFunctionBarView () @interface KBFunctionBarView ()
@property (nonatomic, strong) UIView *leftContainer; // @property (nonatomic, strong) UIView *leftContainer; //
@property (nonatomic, strong) UIView *rightContainer; // @property (nonatomic, strong) UIView *rightContainer; //
@property (nonatomic, strong) NSArray<UIButton *> *leftButtonsInternal; @property (nonatomic, strong) NSArray<UIButton *> *leftButtonsInternal;
@property (nonatomic, strong) NSArray<UIButton *> *rightButtonsInternal; @property (nonatomic, strong) NSArray<UIButton *> *rightButtonsInternal;
@property (nonatomic, strong) UIButton *globeButtonInternal; //
@end @end
@implementation KBFunctionBarView @implementation KBFunctionBarView
@@ -38,6 +40,7 @@
- (void)buildUI { - (void)buildUI {
// 便 // 便
[self addSubview:self.leftContainer]; [self addSubview:self.leftContainer];
[self addSubview:self.globeButtonInternal];
[self addSubview:self.rightContainer]; [self addSubview:self.rightContainer];
[self.rightContainer mas_makeConstraints:^(MASConstraintMaker *make) { [self.rightContainer mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -46,8 +49,15 @@
make.height.mas_equalTo(36); make.height.mas_equalTo(36);
}]; }];
[self.leftContainer mas_makeConstraints:^(MASConstraintMaker *make) { //
[self.globeButtonInternal mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(12); make.left.equalTo(self.mas_left).offset(12);
make.centerY.equalTo(self.mas_centerY);
make.width.height.mas_equalTo(32);
}];
[self.leftContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.globeButtonInternal.mas_right).offset(8);
make.right.equalTo(self.rightContainer.mas_left).offset(-12); make.right.equalTo(self.rightContainer.mas_left).offset(-12);
make.centerY.equalTo(self.mas_centerY); make.centerY.equalTo(self.mas_centerY);
make.height.mas_equalTo(36); make.height.mas_equalTo(36);
@@ -113,6 +123,9 @@
} }
self.rightButtonsInternal = rightBtns.copy; self.rightButtonsInternal = rightBtns.copy;
//
[self kb_refreshGlobeVisibility];
} }
#pragma mark - Actions #pragma mark - Actions
@@ -158,4 +171,56 @@
return _rightContainer; return _rightContainer;
} }
- (UIButton *)globeButtonInternal {
if (!_globeButtonInternal) {
_globeButtonInternal = [UIButton buttonWithType:UIButtonTypeSystem];
_globeButtonInternal.layer.cornerRadius = 16;
_globeButtonInternal.layer.masksToBounds = YES;
_globeButtonInternal.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
[_globeButtonInternal setTitle:@"🌐" forState:UIControlStateNormal];
[_globeButtonInternal setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
return _globeButtonInternal;
}
#pragma mark - Globe (Input Mode Switch)
- (void)kb_refreshGlobeVisibility {
UIInputViewController *ivc = KBFindInputViewController(self);
BOOL needSwitchKey = YES;
if (ivc && [ivc respondsToSelector:@selector(needsInputModeSwitchKey)]) {
needSwitchKey = ivc.needsInputModeSwitchKey;
}
self.globeButtonInternal.hidden = !needSwitchKey;
//
[self.leftContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
if (needSwitchKey) {
make.left.equalTo(self.globeButtonInternal.mas_right).offset(8);
} else {
make.left.equalTo(self.mas_left).offset(12);
}
make.right.equalTo(self.rightContainer.mas_left).offset(-12);
make.centerY.equalTo(self.mas_centerY);
make.height.mas_equalTo(36);
}];
//
[self.globeButtonInternal removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];
if (needSwitchKey && ivc) {
SEL sel = NSSelectorFromString(@"handleInputModeListFromView:withEvent:");
if ([ivc respondsToSelector:sel]) {
[self.globeButtonInternal addTarget:ivc action:sel forControlEvents:UIControlEventAllTouchEvents];
} else {
[self.globeButtonInternal addTarget:ivc action:@selector(advanceToNextInputMode) forControlEvents:UIControlEventTouchUpInside];
}
}
}
- (void)didMoveToWindow {
[super didMoveToWindow];
[self kb_refreshGlobeVisibility];
}
@end @end

View File

@@ -6,11 +6,13 @@
// //
#import "KBToolBar.h" #import "KBToolBar.h"
#import "KBResponderUtils.h" // UIInputViewController
@interface KBToolBar () @interface KBToolBar ()
@property (nonatomic, strong) UIView *leftContainer; @property (nonatomic, strong) UIView *leftContainer;
@property (nonatomic, strong) NSArray<UIButton *> *leftButtonsInternal; @property (nonatomic, strong) NSArray<UIButton *> *leftButtonsInternal;
@property (nonatomic, strong) UIButton *settingsButtonInternal; @property (nonatomic, strong) UIButton *settingsButtonInternal;
@property (nonatomic, strong) UIButton *globeButtonInternal; //
@end @end
@implementation KBToolBar @implementation KBToolBar
@@ -50,6 +52,7 @@
- (void)setupUI { - (void)setupUI {
[self addSubview:self.leftContainer]; [self addSubview:self.leftContainer];
[self addSubview:self.settingsButtonInternal]; [self addSubview:self.settingsButtonInternal];
[self addSubview:self.globeButtonInternal];
// //
[self.settingsButtonInternal mas_makeConstraints:^(MASConstraintMaker *make) { [self.settingsButtonInternal mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -58,9 +61,16 @@
make.width.height.mas_equalTo(32); make.width.height.mas_equalTo(32);
}]; }];
//
[self.globeButtonInternal mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(12);
make.centerY.equalTo(self.mas_centerY);
make.width.height.mas_equalTo(32);
}];
// //
[self.leftContainer mas_makeConstraints:^(MASConstraintMaker *make) { [self.leftContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(12); make.left.equalTo(self.globeButtonInternal.mas_right).offset(8);
make.right.equalTo(self.settingsButtonInternal.mas_left).offset(-12); make.right.equalTo(self.settingsButtonInternal.mas_left).offset(-12);
make.centerY.equalTo(self.mas_centerY); make.centerY.equalTo(self.mas_centerY);
make.height.mas_equalTo(32); make.height.mas_equalTo(32);
@@ -89,6 +99,9 @@
make.right.equalTo(self.leftContainer.mas_right); make.right.equalTo(self.leftContainer.mas_right);
}]; }];
self.leftButtonsInternal = buttons.copy; self.leftButtonsInternal = buttons.copy;
//
[self kb_refreshGlobeVisibility];
} }
- (UIButton *)buildActionButtonAtIndex:(NSInteger)idx { - (UIButton *)buildActionButtonAtIndex:(NSInteger)idx {
@@ -142,4 +155,59 @@
return _settingsButtonInternal; return _settingsButtonInternal;
} }
- (UIButton *)globeButtonInternal {
if (!_globeButtonInternal) {
_globeButtonInternal = [UIButton buttonWithType:UIButtonTypeSystem];
_globeButtonInternal.layer.cornerRadius = 16;
_globeButtonInternal.layer.masksToBounds = YES;
_globeButtonInternal.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
[_globeButtonInternal setTitle:@"🌐" forState:UIControlStateNormal];
[_globeButtonInternal setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
return _globeButtonInternal;
}
#pragma mark - Globe (Input Mode Switch)
// 宿
- (void)kb_refreshGlobeVisibility {
UIInputViewController *ivc = KBFindInputViewController(self);
BOOL needSwitchKey = YES;
if (ivc && [ivc respondsToSelector:@selector(needsInputModeSwitchKey)]) {
needSwitchKey = ivc.needsInputModeSwitchKey; // YES
}
self.globeButtonInternal.hidden = !needSwitchKey;
// leftContainer 12
[self.leftContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
if (needSwitchKey) {
make.left.equalTo(self.globeButtonInternal.mas_right).offset(8);
} else {
make.left.equalTo(self.mas_left).offset(12);
}
make.right.equalTo(self.settingsButtonInternal.mas_left).offset(-12);
make.centerY.equalTo(self.mas_centerY);
make.height.mas_equalTo(32);
}];
//
//
[self.globeButtonInternal removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];
if (needSwitchKey && ivc) {
SEL sel = NSSelectorFromString(@"handleInputModeListFromView:withEvent:");
if ([ivc respondsToSelector:sel]) {
[self.globeButtonInternal addTarget:ivc action:sel forControlEvents:UIControlEventAllTouchEvents];
} else {
// 退
[self.globeButtonInternal addTarget:ivc action:@selector(advanceToNextInputMode) forControlEvents:UIControlEventTouchUpInside];
}
}
}
- (void)didMoveToWindow {
[super didMoveToWindow];
[self kb_refreshGlobeVisibility];
}
@end @end