Merge branch 'dev_联想' into dev_st
This commit is contained in:
@@ -11,14 +11,17 @@
|
||||
#import "KBFunctionView.h"
|
||||
#import "KBKey.h"
|
||||
#import "KBEmojiPanelView.h"
|
||||
#import "KBSuggestionBarView.h"
|
||||
#import "Masonry.h"
|
||||
#import "KBSkinManager.h"
|
||||
|
||||
@interface KBKeyBoardMainView ()<KBToolBarDelegate, KBKeyboardViewDelegate, KBEmojiPanelViewDelegate>
|
||||
@interface KBKeyBoardMainView ()<KBToolBarDelegate, KBKeyboardViewDelegate, KBEmojiPanelViewDelegate, KBSuggestionBarViewDelegate>
|
||||
@property (nonatomic, strong) KBToolBar *topBar;
|
||||
@property (nonatomic, strong) KBSuggestionBarView *suggestionBar;
|
||||
@property (nonatomic, strong) KBKeyboardView *keyboardView;
|
||||
@property (nonatomic, strong) KBEmojiPanelView *emojiView;
|
||||
@property (nonatomic, assign) BOOL emojiPanelVisible;
|
||||
@property (nonatomic, assign) BOOL suggestionBarHasItems;
|
||||
// 注意:功能面板的展示/隐藏由外部控制器决定,此处不再直接管理显隐
|
||||
@end
|
||||
@implementation KBKeyBoardMainView
|
||||
@@ -32,9 +35,17 @@
|
||||
self.topBar = [[KBToolBar alloc] init];
|
||||
self.topBar.delegate = self;
|
||||
[self addSubview:self.topBar];
|
||||
|
||||
// 联想栏
|
||||
self.suggestionBar = [[KBSuggestionBarView alloc] init];
|
||||
self.suggestionBar.delegate = self;
|
||||
self.suggestionBar.hidden = YES;
|
||||
[self addSubview:self.suggestionBar];
|
||||
|
||||
// 键盘区域(高度按照设计值做等比缩放,避免不同机型上按键被压缩/拉伸)
|
||||
CGFloat keyboardAreaHeight = KBFit(200.0f);
|
||||
CGFloat bottomInset = KBFit(4.0f);
|
||||
// CGFloat topBarHeight = KBFit(40.0f);
|
||||
CGFloat barSpacing = KBFit(6.0f);
|
||||
|
||||
self.keyboardView = [[KBKeyboardView alloc] init];
|
||||
@@ -55,11 +66,26 @@
|
||||
make.edges.equalTo(self);
|
||||
}];
|
||||
|
||||
// [self.topBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
// make.left.right.equalTo(self);
|
||||
// make.top.equalTo(self.mas_top).offset(0);
|
||||
// make.height.mas_equalTo(topBarHeight);
|
||||
// }];
|
||||
[self.topBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self);
|
||||
make.top.equalTo(self.mas_top).offset(0);
|
||||
make.bottom.equalTo(self.keyboardView.mas_top).offset(0);
|
||||
}];
|
||||
|
||||
[self.suggestionBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self);
|
||||
make.top.equalTo(self.topBar);
|
||||
make.bottom.equalTo(self.topBar);
|
||||
}];
|
||||
|
||||
[self.keyboardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.topBar.mas_bottom).offset(barSpacing);
|
||||
}];
|
||||
// 功能面板切换交由外部控制器处理;此处不直接创建/管理
|
||||
}
|
||||
return self;
|
||||
@@ -75,17 +101,24 @@
|
||||
} else {
|
||||
self.keyboardView.hidden = NO;
|
||||
self.topBar.hidden = NO;
|
||||
self.suggestionBar.hidden = !self.suggestionBarHasItems;
|
||||
}
|
||||
|
||||
void (^changes)(void) = ^{
|
||||
self.emojiView.alpha = visible ? 1.0 : 0.0;
|
||||
self.keyboardView.alpha = visible ? 0.0 : 1.0;
|
||||
self.topBar.alpha = visible ? 0.0 : 1.0;
|
||||
self.suggestionBar.alpha = visible ? 0.0 : (self.suggestionBarHasItems ? 1.0 : 0.0);
|
||||
};
|
||||
void (^completion)(BOOL) = ^(BOOL finished) {
|
||||
self.emojiView.hidden = !visible;
|
||||
self.keyboardView.hidden = visible;
|
||||
self.topBar.hidden = visible;
|
||||
if (visible) {
|
||||
self.suggestionBar.hidden = YES;
|
||||
} else {
|
||||
self.suggestionBar.hidden = !self.suggestionBarHasItems;
|
||||
}
|
||||
};
|
||||
|
||||
if (animated) {
|
||||
@@ -213,10 +246,34 @@
|
||||
if ([self.topBar respondsToSelector:@selector(kb_applyTheme)]) {
|
||||
[self.topBar kb_applyTheme];
|
||||
}
|
||||
[self.suggestionBar applyTheme:mgr.current];
|
||||
[self.keyboardView reloadKeys];
|
||||
if (self.emojiView) {
|
||||
[self.emojiView applyTheme:mgr.current];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Suggestions
|
||||
|
||||
- (void)kb_setSuggestions:(NSArray<NSString *> *)suggestions {
|
||||
self.suggestionBarHasItems = (suggestions.count > 0);
|
||||
[self.suggestionBar updateSuggestions:suggestions];
|
||||
|
||||
if (self.emojiPanelVisible) {
|
||||
self.suggestionBar.hidden = YES;
|
||||
self.suggestionBar.alpha = 0.0;
|
||||
} else {
|
||||
self.suggestionBar.hidden = !self.suggestionBarHasItems;
|
||||
self.suggestionBar.alpha = self.suggestionBarHasItems ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - KBSuggestionBarViewDelegate
|
||||
|
||||
- (void)suggestionBarView:(KBSuggestionBarView *)view didSelectSuggestion:(NSString *)suggestion {
|
||||
if ([self.delegate respondsToSelector:@selector(keyBoardMainView:didSelectSuggestion:)]) {
|
||||
[self.delegate keyBoardMainView:self didSelectSuggestion:suggestion];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user