@@ -22,6 +22,8 @@ - (void)layoutSubviews
22
22
23
23
@end
24
24
25
+ static CGFloat sysKeyboardEndY = 0 ;
26
+
25
27
@interface ChatKeyboard ()<UITextViewDelegate,UIScrollViewDelegate>
26
28
// 表情
27
29
@property (nonatomic , strong ) UIView *facesKeyboard;
@@ -345,9 +347,9 @@ - (void)systemKeyboardWillShow:(NSNotification *)note
345
347
{
346
348
// 重置所有按钮selected
347
349
[self reloadSwitchButtons ];
348
-
349
350
// 获取系统键盘高度
350
351
CGFloat systemKbHeight = [note.userInfo[@" UIKeyboardBoundsUserInfoKey" ]CGRectValue].size .height ;
352
+ // 记录Y值
351
353
// 将自定义键盘跟随位移
352
354
[self customKeyboardMove: SCREEN_HEIGHT - systemKbHeight - Height (self .messageBar.frame)];
353
355
}
@@ -467,10 +469,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
467
469
NSLog (@" -------old ---%@ " ,change[@" old" ]);
468
470
if (change[@" new" ] != change[@" old" ]) {
469
471
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 ];
474
473
}
475
474
}
476
475
@@ -487,6 +486,15 @@ - (void)reloadSwitchButtons
487
486
self.swtHandleButton .selected = NO ;
488
487
}
489
488
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
+
490
498
#pragma mark - 拍摄 , 照片 ,视频按钮点击
491
499
- (void )handleButtonClick : (ChatHandleButton *)button
492
500
{
@@ -517,6 +525,11 @@ - (void)emotionClick:(UIButton *)emotionBtn
517
525
// 获取点击的表情
518
526
NSString *emotionKey = [NSString stringWithFormat: @" ChatEmotion_%li " ,emotionBtn.tag - 999 ];
519
527
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;
520
533
NSLog (@" --------当前点击了表情 : ------------------%@ " ,emotionName);
521
534
}
522
535
0 commit comments