@@ -231,11 +231,12 @@ - (UITextView *)msgTextView
231
231
_msgTextView.font = FontSet (14 );
232
232
_msgTextView.showsVerticalScrollIndicator = NO ;
233
233
_msgTextView.showsHorizontalScrollIndicator = NO ;
234
- _msgTextView.scrollEnabled = NO ;
235
234
_msgTextView.returnKeyType = UIReturnKeySend;
236
235
_msgTextView.enablesReturnKeyAutomatically = YES ;
237
236
_msgTextView.delegate = self;
238
237
ViewRadius (_msgTextView, 5 );
238
+ // 观察者监听高度变化
239
+ [_msgTextView addObserver: self forKeyPath: @" contentSize" options: NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context: nil ];
239
240
}
240
241
return _msgTextView;
241
242
}
@@ -318,11 +319,11 @@ - (void)configUIFrame
318
319
{
319
320
self.messageBar .frame = Frame (0 , 0 , SCREEN_WITDTH, 49 ); // 消息栏
320
321
self.audioButton .frame = Frame (10 , (Height (self.messageBar .frame ) - 30 )*0.5 , 30 , 30 ); // 语音按钮
321
- self.audioLpButton .frame = Frame (MaxX (self.audioButton .frame )+15 ,(Height (self.messageBar .frame )-34 )*0.5 , SCREEN_WITDTH - 155 , 34 ); // 长按录音按钮
322
+ self.audioLpButton .frame = Frame (MaxX (self.audioButton .frame )+15 ,(Height (self.messageBar .frame )-35 )*0.5 , SCREEN_WITDTH - 155 , 35 ); // 长按录音按钮
322
323
self.msgTextView .frame = self.audioLpButton .frame ; // 输入框
323
324
self.swtFaceButton .frame = Frame (MaxX (self.msgTextView .frame )+15 , (Height (self.messageBar .frame )-30 )*0.5 ,30 , 30 ); // 表情键盘切换按钮
324
325
self.swtHandleButton .frame = Frame (MaxX (self.swtFaceButton .frame )+15 , (Height (self.messageBar .frame )-30 )*0.5 , 30 , 30 ); // 加号按钮切换操作键盘
325
- self.keyBoardContainer .frame = Frame (0 ,Height (self.messageBar .frame ), SCREEN_WITDTH,CUSTOMKEYBOARD_HEIGHT - Height (self.messageBar .frame )); // 自定义键盘容器
326
+ self.keyBoardContainer .frame = Frame (0 ,Height (self.messageBar .frame ), SCREEN_WITDTH,CTKEYBOARD_DEFAULTHEIGHT - Height (self.messageBar .frame )); // 自定义键盘容器
326
327
self.handleKeyboard .frame = self.keyBoardContainer .bounds ;// 键盘操作栏
327
328
self.facesKeyboard .frame = self.keyBoardContainer .bounds ; // 表情键盘部分
328
329
@@ -388,6 +389,14 @@ - (void)audioLpButtonTouchUpInside:(UIButton *)audioLpButton
388
389
#pragma mark - 切换到表情键盘
389
390
- (void )switchFaceKeyboard : (UIButton *)swtFaceButton
390
391
{
392
+
393
+ if (swtFaceButton.selected ) {
394
+
395
+ }else {
396
+
397
+ }
398
+
399
+
391
400
_msgTextView.hidden = NO ;
392
401
_audioLpButton.hidden = YES ;
393
402
[_msgTextView resignFirstResponder ];
@@ -421,6 +430,25 @@ - (void)textViewDidChange:(UITextView *)textView
421
430
{
422
431
423
432
}
433
+
434
+ #pragma mark - 监听输入框变化 (这里如果放到layout里自动让他布局 , 会稍显麻烦一些 , 所以自动手动控制一下)
435
+ // 这里用contentSize计算较为简单和精确 , 如果计算文字高度 , 还需要加上textView的内间距.
436
+ - (void )observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary <NSKeyValueChangeKey,id> *)change context : (void *)context
437
+ {
438
+ CGFloat oldHeight = [change[@" old" ]CGSizeValue].height ;
439
+ CGFloat newHeight = [change[@" new" ]CGSizeValue].height ;
440
+ if (oldHeight <=0 || newHeight <=0 ) return ;
441
+ NSLog (@" ------new ----%@ " ,change[@" new" ]);
442
+ NSLog (@" -------old ---%@ " ,change[@" old" ]);
443
+ if (change[@" new" ] != change[@" old" ]) {
444
+ NSLog (@" 高度变化" );
445
+ self.messageBar .frame = Frame (0 , 0 , SCREEN_WITDTH, newHeight+MinY (self.msgTextView .frame )*2 );
446
+ self.msgTextView .frame = Frame (MinX (self.msgTextView .frame ),(Height (self.messageBar .frame )-newHeight)*0.5 , Width (self.msgTextView .frame ), newHeight);
447
+ self.keyBoardContainer .frame = Frame (0 , MaxY (self.messageBar .frame ), SCREEN_WITDTH, Height (self.keyBoardContainer .frame ));
448
+ 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 ));
449
+ }
450
+ }
451
+
424
452
- (BOOL )textView : (UITextView *)textView shouldChangeTextInRange : (NSRange )range replacementText : (NSString *)text
425
453
{
426
454
return YES ;
@@ -471,4 +499,9 @@ - (void)sendEmotionMessage:(UIButton *)emotionSendBtn
471
499
472
500
}
473
501
502
+
503
+ - (void )dealloc
504
+ {
505
+ [self .msgTextView removeObserver: self forKeyPath: @" contentSize" ];
506
+ }
474
507
@end
0 commit comments