Skip to content

Commit 185061b

Browse files
author
mengyaoyao
committed
update
1 parent 8ea9158 commit 185061b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

CocoaAsyncSocket_TCP/View/KeyBoard/ChatKeyboard.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ - (void)layoutSubviews
2222

2323
@end
2424

25+
static CGFloat sysKeyboardEndY = 0;
26+
2527
@interface ChatKeyboard ()<UITextViewDelegate,UIScrollViewDelegate>
2628
//表情
2729
@property (nonatomic, strong) UIView *facesKeyboard;
@@ -345,9 +347,9 @@ - (void)systemKeyboardWillShow:(NSNotification *)note
345347
{
346348
//重置所有按钮selected
347349
[self reloadSwitchButtons];
348-
349350
//获取系统键盘高度
350351
CGFloat systemKbHeight = [note.userInfo[@"UIKeyboardBoundsUserInfoKey"]CGRectValue].size.height;
352+
//记录Y值
351353
//将自定义键盘跟随位移
352354
[self customKeyboardMove:SCREEN_HEIGHT - systemKbHeight - Height(self.messageBar.frame)];
353355
}
@@ -467,10 +469,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
467469
NSLog(@"-------old ---%@",change[@"old"]);
468470
if (change[@"new"] != change[@"old"]) {
469471
NSLog(@"高度变化");
470-
self.messageBar.frame = Frame(0, 0, SCREEN_WITDTH, newHeight+MinY(self.msgTextView.frame)*2);
471-
self.msgTextView.frame = Frame(MinX(self.msgTextView.frame),(Height(self.messageBar.frame)-newHeight)*0.5, Width(self.msgTextView.frame), newHeight);
472-
self.keyBoardContainer.frame = Frame(0, MaxY(self.messageBar.frame), SCREEN_WITDTH, Height(self.keyBoardContainer.frame));
473-
self.frame = Frame(0,SCREEN_HEIGHT - Height(self.messageBar.frame) - Height(self.keyBoardContainer.frame)-49, SCREEN_WITDTH,Height(self.keyBoardContainer.frame) + Height(self.messageBar.frame));
472+
[self msgTextViewHeightFit];
474473
}
475474
}
476475

@@ -487,6 +486,15 @@ - (void)reloadSwitchButtons
487486
self.swtHandleButton.selected = NO;
488487
}
489488

489+
#pragma mark - 输入框拉高
490+
- (void)msgTextViewHeightFit
491+
{
492+
self.messageBar.frame = Frame(0, 0, SCREEN_WITDTH, self.msgTextView.contentSize.height +MinY(self.msgTextView.frame)*2);
493+
self.msgTextView.frame = Frame(MinX(self.msgTextView.frame),(Height(self.messageBar.frame)-self.msgTextView.contentSize.height)*0.5, Width(self.msgTextView.frame), self.msgTextView.contentSize.height);
494+
self.keyBoardContainer.frame = Frame(0, MaxY(self.messageBar.frame), SCREEN_WITDTH, Height(self.keyBoardContainer.frame));
495+
self.frame = Frame(0,SCREEN_HEIGHT - Height(self.messageBar.frame) - Height(self.keyBoardContainer.frame)-49, SCREEN_WITDTH,Height(self.keyBoardContainer.frame) + Height(self.messageBar.frame));
496+
}
497+
490498
#pragma mark - 拍摄 , 照片 ,视频按钮点击
491499
- (void)handleButtonClick:(ChatHandleButton *)button
492500
{
@@ -517,6 +525,11 @@ - (void)emotionClick:(UIButton *)emotionBtn
517525
//获取点击的表情
518526
NSString *emotionKey = [NSString stringWithFormat:@"ChatEmotion_%li",emotionBtn.tag - 999];
519527
NSString *emotionName = [self.emotionDict objectForKey:emotionKey];
528+
//获取光标所在位置
529+
NSInteger location = self.msgTextView.selectedRange.location;
530+
NSMutableString *txtStrM = [[NSMutableString alloc]initWithString:self.msgTextView.text];
531+
[txtStrM insertString:emotionName atIndex:location];
532+
self.msgTextView.text = txtStrM;
520533
NSLog(@"--------当前点击了表情 : ------------------%@",emotionName);
521534
}
522535

0 commit comments

Comments
 (0)