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