优化发送输入框
This commit is contained in:
22
keyBoard/Assets.xcassets/AI/ai_sendmessage_icon.imageset/Contents.json
vendored
Normal file
22
keyBoard/Assets.xcassets/AI/ai_sendmessage_icon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename" : "ai_sendmessage_icon@2x.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename" : "ai_sendmessage_icon@3x.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
keyBoard/Assets.xcassets/AI/ai_sendmessage_icon.imageset/ai_sendmessage_icon@2x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_sendmessage_icon.imageset/ai_sendmessage_icon@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
BIN
keyBoard/Assets.xcassets/AI/ai_sendmessage_icon.imageset/ai_sendmessage_icon@3x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_sendmessage_icon.imageset/ai_sendmessage_icon@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -1075,7 +1075,7 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
|||||||
[self.popView dismiss];
|
[self.popView dismiss];
|
||||||
}
|
}
|
||||||
|
|
||||||
CGFloat customViewHeight = KB_SCREEN_HEIGHT * 0.7;
|
CGFloat customViewHeight = KB_SCREEN_HEIGHT * 0.75;
|
||||||
KBAICommentView *customView = [[KBAICommentView alloc]
|
KBAICommentView *customView = [[KBAICommentView alloc]
|
||||||
initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)];
|
initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)];
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
@interface KBAICommentInputView () <UITextFieldDelegate>
|
@interface KBAICommentInputView () <UITextFieldDelegate>
|
||||||
|
|
||||||
@property(nonatomic, strong) UIView *containerView;
|
@property(nonatomic, strong) UIView *containerView;
|
||||||
@property(nonatomic, strong) UIImageView *avatarImageView;
|
//@property(nonatomic, strong) UIImageView *avatarImageView;
|
||||||
@property(nonatomic, strong) UITextField *textField;
|
@property(nonatomic, strong) UITextField *textField;
|
||||||
|
@property(nonatomic, strong) UILabel *placeholderLabel;
|
||||||
@property(nonatomic, strong) UIButton *sendButton;
|
@property(nonatomic, strong) UIButton *sendButton;
|
||||||
@property(nonatomic, strong) UIView *topLine;
|
@property(nonatomic, strong) UIView *topLine;
|
||||||
|
|
||||||
@@ -31,12 +32,13 @@
|
|||||||
#pragma mark - UI Setup
|
#pragma mark - UI Setup
|
||||||
|
|
||||||
- (void)setupUI {
|
- (void)setupUI {
|
||||||
self.backgroundColor = [UIColor whiteColor];
|
self.backgroundColor = [UIColor colorWithHex:0x797979 alpha:0.49];
|
||||||
|
|
||||||
[self addSubview:self.topLine];
|
[self addSubview:self.topLine];
|
||||||
[self addSubview:self.avatarImageView];
|
// [self addSubview:self.avatarImageView];
|
||||||
[self addSubview:self.containerView];
|
[self addSubview:self.containerView];
|
||||||
[self.containerView addSubview:self.textField];
|
[self.containerView addSubview:self.textField];
|
||||||
|
[self addSubview:self.placeholderLabel];
|
||||||
[self addSubview:self.sendButton];
|
[self addSubview:self.sendButton];
|
||||||
|
|
||||||
[self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
[self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
@@ -44,17 +46,17 @@
|
|||||||
make.height.mas_equalTo(0.5);
|
make.height.mas_equalTo(0.5);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
// [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
make.left.equalTo(self).offset(12);
|
// make.left.equalTo(self).offset(12);
|
||||||
make.centerY.equalTo(self);
|
// make.centerY.equalTo(self);
|
||||||
make.width.height.mas_equalTo(32);
|
// make.width.height.mas_equalTo(32);
|
||||||
}];
|
// }];
|
||||||
|
|
||||||
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
make.left.equalTo(self.avatarImageView.mas_right).offset(10);
|
make.left.equalTo(self).offset(12);
|
||||||
make.right.equalTo(self.sendButton.mas_left).offset(-10);
|
make.right.equalTo(self.sendButton.mas_left).offset(-12);
|
||||||
make.centerY.equalTo(self);
|
make.centerY.equalTo(self);
|
||||||
make.height.mas_equalTo(36);
|
make.height.mas_equalTo(52);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
@@ -69,17 +71,23 @@
|
|||||||
make.width.mas_equalTo(50);
|
make.width.mas_equalTo(50);
|
||||||
make.height.mas_equalTo(30);
|
make.height.mas_equalTo(30);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
[self.placeholderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
|
make.center.equalTo(self);
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Public Methods
|
#pragma mark - Public Methods
|
||||||
|
|
||||||
- (void)setPlaceholder:(NSString *)placeholder {
|
- (void)setPlaceholder:(NSString *)placeholder {
|
||||||
_placeholder = placeholder;
|
_placeholder = placeholder;
|
||||||
self.textField.placeholder = placeholder;
|
self.placeholderLabel.text = placeholder;
|
||||||
|
[self updatePlaceholderVisibility];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clearText {
|
- (void)clearText {
|
||||||
self.textField.text = @"";
|
self.textField.text = @"";
|
||||||
|
[self updatePlaceholderVisibility];
|
||||||
[self updateSendButtonState];
|
[self updateSendButtonState];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,13 +105,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)textFieldDidChange:(UITextField *)textField {
|
- (void)textFieldDidChange:(UITextField *)textField {
|
||||||
|
[self updatePlaceholderVisibility];
|
||||||
[self updateSendButtonState];
|
[self updateSendButtonState];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateSendButtonState {
|
- (void)updateSendButtonState {
|
||||||
BOOL hasText = self.textField.text.length > 0;
|
BOOL hasText = self.textField.text.length > 0;
|
||||||
self.sendButton.enabled = hasText;
|
self.sendButton.enabled = hasText;
|
||||||
self.sendButton.alpha = hasText ? 1.0 : 0.5;
|
// self.sendButton.alpha = hasText ? 1.0 : 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - UITextFieldDelegate
|
#pragma mark - UITextFieldDelegate
|
||||||
@@ -113,6 +122,15 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
|
||||||
|
[self updatePlaceholderVisibility];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)textFieldDidEndEditing:(UITextField *)textField {
|
||||||
|
[self updatePlaceholderVisibility];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Lazy Loading
|
#pragma mark - Lazy Loading
|
||||||
|
|
||||||
- (UIView *)topLine {
|
- (UIView *)topLine {
|
||||||
@@ -123,25 +141,24 @@
|
|||||||
return _topLine;
|
return _topLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImageView *)avatarImageView {
|
//- (UIImageView *)avatarImageView {
|
||||||
if (!_avatarImageView) {
|
// if (!_avatarImageView) {
|
||||||
_avatarImageView = [[UIImageView alloc] init];
|
// _avatarImageView = [[UIImageView alloc] init];
|
||||||
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
// _avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||||
_avatarImageView.layer.cornerRadius = 16;
|
// _avatarImageView.layer.cornerRadius = 16;
|
||||||
_avatarImageView.layer.masksToBounds = YES;
|
// _avatarImageView.layer.masksToBounds = YES;
|
||||||
_avatarImageView.backgroundColor = [UIColor systemGray5Color];
|
// _avatarImageView.backgroundColor = [UIColor systemGray5Color];
|
||||||
_avatarImageView.image = [UIImage systemImageNamed:@"person.circle.fill"];
|
// _avatarImageView.image = [UIImage systemImageNamed:@"person.circle.fill"];
|
||||||
_avatarImageView.tintColor = [UIColor systemGray3Color];
|
// _avatarImageView.tintColor = [UIColor systemGray3Color];
|
||||||
}
|
// }
|
||||||
return _avatarImageView;
|
// return _avatarImageView;
|
||||||
}
|
//}
|
||||||
|
|
||||||
- (UIView *)containerView {
|
- (UIView *)containerView {
|
||||||
if (!_containerView) {
|
if (!_containerView) {
|
||||||
_containerView = [[UIView alloc] init];
|
_containerView = [[UIView alloc] init];
|
||||||
_containerView.backgroundColor = [UIColor systemGray6Color];
|
// _containerView.layer.cornerRadius = 26;
|
||||||
_containerView.layer.cornerRadius = 18;
|
// _containerView.layer.masksToBounds = YES;
|
||||||
_containerView.layer.masksToBounds = YES;
|
|
||||||
}
|
}
|
||||||
return _containerView;
|
return _containerView;
|
||||||
}
|
}
|
||||||
@@ -149,27 +166,42 @@
|
|||||||
- (UITextField *)textField {
|
- (UITextField *)textField {
|
||||||
if (!_textField) {
|
if (!_textField) {
|
||||||
_textField = [[UITextField alloc] init];
|
_textField = [[UITextField alloc] init];
|
||||||
_textField.placeholder = @"说点什么...";
|
_textField.textColor = [UIColor whiteColor];
|
||||||
|
_textField.textAlignment = NSTextAlignmentLeft;
|
||||||
_textField.font = [UIFont systemFontOfSize:14];
|
_textField.font = [UIFont systemFontOfSize:14];
|
||||||
_textField.delegate = self;
|
_textField.delegate = self;
|
||||||
_textField.returnKeyType = UIReturnKeySend;
|
_textField.returnKeyType = UIReturnKeySend;
|
||||||
[_textField addTarget:self
|
[_textField addTarget:self
|
||||||
action:@selector(textFieldDidChange:)
|
action:@selector(textFieldDidChange:)
|
||||||
forControlEvents:UIControlEventEditingChanged];
|
forControlEvents:UIControlEventEditingChanged];
|
||||||
|
[self updatePlaceholderVisibility];
|
||||||
}
|
}
|
||||||
return _textField;
|
return _textField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (UILabel *)placeholderLabel {
|
||||||
|
if (!_placeholderLabel) {
|
||||||
|
_placeholderLabel = [[UILabel alloc] init];
|
||||||
|
_placeholderLabel.text = @"Send A Message";
|
||||||
|
_placeholderLabel.textColor = [UIColor whiteColor];
|
||||||
|
_placeholderLabel.font = [UIFont systemFontOfSize:14];
|
||||||
|
_placeholderLabel.textAlignment = NSTextAlignmentCenter;
|
||||||
|
_placeholderLabel.userInteractionEnabled = NO;
|
||||||
|
}
|
||||||
|
return _placeholderLabel;
|
||||||
|
}
|
||||||
|
|
||||||
- (UIButton *)sendButton {
|
- (UIButton *)sendButton {
|
||||||
if (!_sendButton) {
|
if (!_sendButton) {
|
||||||
_sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
_sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
[_sendButton setTitle:@"发送" forState:UIControlStateNormal];
|
// [_sendButton setTitle:@"发送" forState:UIControlStateNormal];
|
||||||
[_sendButton setTitleColor:[UIColor systemBlueColor]
|
// [_sendButton setTitleColor:[UIColor systemBlueColor]
|
||||||
forState:UIControlStateNormal];
|
// forState:UIControlStateNormal];
|
||||||
_sendButton.titleLabel.font = [UIFont systemFontOfSize:15
|
// _sendButton.titleLabel.font = [UIFont systemFontOfSize:15
|
||||||
weight:UIFontWeightMedium];
|
// weight:UIFontWeightMedium];
|
||||||
|
[_sendButton setImage:[UIImage imageNamed:@"ai_sendmessage_icon"] forState:UIControlStateNormal];
|
||||||
_sendButton.enabled = NO;
|
_sendButton.enabled = NO;
|
||||||
_sendButton.alpha = 0.5;
|
// _sendButton.alpha = 0.5;
|
||||||
[_sendButton addTarget:self
|
[_sendButton addTarget:self
|
||||||
action:@selector(sendButtonTapped)
|
action:@selector(sendButtonTapped)
|
||||||
forControlEvents:UIControlEventTouchUpInside];
|
forControlEvents:UIControlEventTouchUpInside];
|
||||||
@@ -177,4 +209,11 @@
|
|||||||
return _sendButton;
|
return _sendButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Private
|
||||||
|
|
||||||
|
- (void)updatePlaceholderVisibility {
|
||||||
|
BOOL hasText = self.textField.text.length > 0;
|
||||||
|
self.placeholderLabel.hidden = hasText;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -189,8 +189,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
[self.inputView mas_makeConstraints:^(MASConstraintMaker *make) {
|
[self.inputView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
make.left.right.equalTo(self);
|
make.left.right.equalTo(self).inset(12);
|
||||||
make.height.mas_equalTo(50);
|
make.height.mas_equalTo(52);
|
||||||
self.inputBottomConstraint =
|
self.inputBottomConstraint =
|
||||||
make.bottom.equalTo(self).offset(-KB_SafeAreaBottom());
|
make.bottom.equalTo(self).offset(-KB_SafeAreaBottom());
|
||||||
}];
|
}];
|
||||||
@@ -846,8 +846,9 @@ static NSInteger const kRepliesLoadCount = 5;
|
|||||||
- (KBAICommentInputView *)inputView {
|
- (KBAICommentInputView *)inputView {
|
||||||
if (!_inputView) {
|
if (!_inputView) {
|
||||||
_inputView = [[KBAICommentInputView alloc] init];
|
_inputView = [[KBAICommentInputView alloc] init];
|
||||||
_inputView.placeholder = @"说点什么...";
|
_inputView.placeholder = @"Send A Message";
|
||||||
|
_inputView.layer.cornerRadius = 26;
|
||||||
|
_inputView.clipsToBounds = true;
|
||||||
__weak typeof(self) weakSelf = self;
|
__weak typeof(self) weakSelf = self;
|
||||||
_inputView.onSend = ^(NSString *text) {
|
_inputView.onSend = ^(NSString *text) {
|
||||||
[weakSelf sendCommentWithText:text];
|
[weakSelf sendCommentWithText:text];
|
||||||
|
|||||||
@@ -791,7 +791,7 @@
|
|||||||
- (UIButton *)sendButton {
|
- (UIButton *)sendButton {
|
||||||
if (!_sendButton) {
|
if (!_sendButton) {
|
||||||
_sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
_sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
[_sendButton setTitle:KBLocalized(@"发送") forState:UIControlStateNormal];
|
[_sendButton setTitle:KBLocalized(@"send") forState:UIControlStateNormal];
|
||||||
[_sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
[_sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||||
_sendButton.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
_sendButton.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
||||||
_sendButton.backgroundColor = [UIColor colorWithRed:0.2 green:0.6 blue:1.0 alpha:1.0];
|
_sendButton.backgroundColor = [UIColor colorWithRed:0.2 green:0.6 blue:1.0 alpha:1.0];
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
|
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
|
||||||
|
|
||||||
/// 右侧搜索按钮
|
/// 右侧搜索按钮
|
||||||
@property (nonatomic, strong) UIButton *searchButton;
|
//@property (nonatomic, strong) UIButton *searchButton;
|
||||||
|
|
||||||
/// 标题数组
|
/// 标题数组
|
||||||
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
[self setupUI];
|
[self setupUI];
|
||||||
|
|
||||||
/// 2:绑定事件
|
/// 2:绑定事件
|
||||||
[self bindActions];
|
// [self bindActions];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - 1:控件初始化
|
#pragma mark - 1:控件初始化
|
||||||
@@ -69,12 +69,12 @@
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
// 添加搜索按钮
|
// 添加搜索按钮
|
||||||
[self.kb_navView addSubview:self.searchButton];
|
// [self.kb_navView addSubview:self.searchButton];
|
||||||
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
// [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
make.right.equalTo(self.kb_navView).offset(-16);
|
// make.right.equalTo(self.kb_navView).offset(-16);
|
||||||
make.centerY.equalTo(self.kb_backButton);
|
// make.centerY.equalTo(self.kb_backButton);
|
||||||
make.width.height.mas_equalTo(24);
|
// make.width.height.mas_equalTo(24);
|
||||||
}];
|
// }];
|
||||||
|
|
||||||
// 添加列表容器
|
// 添加列表容器
|
||||||
[self.view addSubview:self.listContainerView];
|
[self.view addSubview:self.listContainerView];
|
||||||
@@ -94,9 +94,9 @@
|
|||||||
|
|
||||||
#pragma mark - 2:绑定事件
|
#pragma mark - 2:绑定事件
|
||||||
|
|
||||||
- (void)bindActions {
|
//- (void)bindActions {
|
||||||
[self.searchButton addTarget:self action:@selector(searchButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
// [self.searchButton addTarget:self action:@selector(searchButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||||
}
|
//}
|
||||||
|
|
||||||
#pragma mark - Actions
|
#pragma mark - Actions
|
||||||
|
|
||||||
@@ -189,16 +189,16 @@
|
|||||||
return _listContainerView;
|
return _listContainerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIButton *)searchButton {
|
//- (UIButton *)searchButton {
|
||||||
if (!_searchButton) {
|
// if (!_searchButton) {
|
||||||
_searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
// _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
if (@available(iOS 13.0, *)) {
|
// if (@available(iOS 13.0, *)) {
|
||||||
UIImage *searchImage = [UIImage systemImageNamed:@"magnifyingglass"];
|
// UIImage *searchImage = [UIImage systemImageNamed:@"magnifyingglass"];
|
||||||
[_searchButton setImage:searchImage forState:UIControlStateNormal];
|
// [_searchButton setImage:searchImage forState:UIControlStateNormal];
|
||||||
_searchButton.tintColor = [UIColor colorWithHex:0x1B1F1A];
|
// _searchButton.tintColor = [UIColor colorWithHex:0x1B1F1A];
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return _searchButton;
|
// return _searchButton;
|
||||||
}
|
//}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@interface UIColor (Extension)
|
@interface UIColor (Extension)
|
||||||
+ (UIColor *)colorWithHex:(int)hexValue;
|
+ (UIColor *)colorWithHex:(int)hexValue;
|
||||||
|
+ (UIColor *)colorWithHex:(int)hexValue alpha:(CGFloat)alpha;
|
||||||
+ (nullable UIColor *)colorWithHexString:(NSString *)hexString;
|
+ (nullable UIColor *)colorWithHexString:(NSString *)hexString;
|
||||||
+ (UIColor *)kb_dynamicColorWithLightColor:(UIColor *)lightColor
|
+ (UIColor *)kb_dynamicColorWithLightColor:(UIColor *)lightColor
|
||||||
darkColor:(UIColor *)darkColor;
|
darkColor:(UIColor *)darkColor;
|
||||||
|
|||||||
Reference in New Issue
Block a user