@@ -41,11 +41,23 @@ @interface ChatKeyboard ()<UITextViewDelegate>
4141@end
4242
4343@implementation ChatKeyboard
44+
45+ // 表情键盘
46+ - (UIView *)facesKeyboard
47+ {
48+ if (!_facesKeyboard) {
49+ _facesKeyboard = [[UIView alloc ]init];
50+ _facesKeyboard.backgroundColor = [UIColor greenColor ];
51+ }
52+ return _facesKeyboard;
53+ }
54+
4455// 操作按钮键盘
4556- (UIView *)handleKeyboard
4657{
4758 if (!_handleKeyboard) {
4859 _handleKeyboard = [[UIView alloc ]init];
60+ _handleKeyboard.backgroundColor = [UIColor redColor ];
4961 NSArray *buttonNames = @[@" 照片" ,@" 拍摄" ,@" 视频" ];
5062 for (NSInteger index = 0 ; index < 3 ; index ++) {
5163 NSInteger colum = index % 3 ;
@@ -135,6 +147,8 @@ - (UIButton *)audioLpButton
135147 _audioLpButton = [UIButton buttonWithType: UIButtonTypeCustom];
136148 [_audioLpButton setTitle: @" 按住说话" forState: UIControlStateNormal];
137149 [_audioLpButton setTitle: @" 松开发送" forState: UIControlStateHighlighted];
150+ [_audioLpButton setTitleColor: UICOLOR_RGB_Alpha (0x333333 , 1 ) forState: UIControlStateNormal];
151+ _audioLpButton.titleLabel .font = FontSet (14 );
138152 // 按下录音按钮
139153 [_audioLpButton addTarget: self action: @selector (audioLpButtonTouchDown: ) forControlEvents: UIControlEventTouchDown];
140154 // 手指离开录音按钮 , 但不松开
@@ -147,6 +161,9 @@ - (UIButton *)audioLpButton
147161 [_audioLpButton addTarget: self action: @selector (audioLpButtonTouchUpInside: ) forControlEvents: UIControlEventTouchUpInside];
148162 // 默认隐藏
149163 _audioLpButton.hidden = YES ;
164+ // 边框,切角
165+ ViewBorder (_audioLpButton, UICOLOR_RGB_Alpha (0x999999 , 1 ), 1 );
166+ ViewRadius (_audioLpButton, 5 );
150167 }
151168 return _audioLpButton;
152169}
@@ -157,13 +174,16 @@ - (instancetype)initWithFrame:(CGRect)frame
157174 [self addSubview: self .messageBar];
158175 [self addSubview: self .facesKeyboard];
159176 [self addSubview: self .handleKeyboard];
177+
178+ // 布局
179+ [self configUIFrame ];
160180 }
161181 return self;
162182}
163183
164- - (void )layoutSubviews
184+ #pragma mark - 初始化布局
185+ - (void )configUIFrame
165186{
166- [super layoutSubviews ];
167187 self.messageBar .frame = Frame (0 , 0 , SCREEN_WITDTH, 49 ); // 消息栏
168188 self.audioButton .frame = Frame (10 , (Height (self.messageBar .frame ) - 30 )*0.5 , 30 , 30 ); // 语音按钮
169189 self.audioLpButton .frame = Frame (MaxX (self.audioButton .frame )+15 ,(Height (self.messageBar .frame )-34 )*0.5 , SCREEN_WITDTH - 155 , 34 ); // 长按录音按钮
@@ -174,10 +194,22 @@ - (void)layoutSubviews
174194 self.facesKeyboard .frame = self.handleKeyboard .frame ; // 表情容器部分
175195}
176196
197+ #pragma mark - 系统键盘即将弹起
198+ - (void )systemKeyboardWillShow : (NSNotification *)note
199+ {
200+ // 获取系统键盘高度
201+ CGFloat systemKbHeight = [note.userInfo[@" UIKeyboardBoundsUserInfoKey" ]CGRectValue].size .height ;
202+ // 将自定义键盘跟随位移
203+ [self customKeyboardMove: SCREEN_HEIGHT - systemKbHeight - Height (self .messageBar.frame)];
204+ }
205+
177206#pragma mark - 切换至语音录制
178207- (void )audioButtonClick : (UIButton *)audioButton
179208{
180-
209+ [_msgTextView resignFirstResponder ];
210+ self.msgTextView .hidden = YES ;
211+ self.audioLpButton .hidden = NO ;
212+ [self customKeyboardMove: SCREEN_HEIGHT - Height (self .messageBar.frame)];
181213}
182214#pragma mark - 语音按钮点击
183215- (void )audioLpButtonTouchDown : (UIButton *)audioLpButton
@@ -207,13 +239,41 @@ - (void)audioLpButtonTouchUpInside:(UIButton *)audioLpButton
207239#pragma mark - 切换到表情键盘
208240- (void )switchFaceKeyboard : (UIButton *)swtFaceButton
209241{
210-
242+ _msgTextView.hidden = NO ;
243+ _audioLpButton.hidden = YES ;
244+ [_msgTextView resignFirstResponder ];
245+ [self bringSubviewToFront: self .facesKeyboard];
246+ // 自定义键盘位移
247+ [self customKeyboardMove: SCREEN_HEIGHT - Height (self .frame)];
211248}
212249#pragma mark - 切换到操作键盘
213250- (void )switchHandleKeyboard : (UIButton *)swtHandleButton
251+ {
252+ _msgTextView.hidden = NO ;
253+ _audioLpButton.hidden = YES ;
254+ [_msgTextView resignFirstResponder ];
255+ [self bringSubviewToFront: self .handleKeyboard];
256+ // 自定义键盘位移
257+ [self customKeyboardMove: SCREEN_HEIGHT - Height (self .frame)];
258+ }
259+
260+ #pragma mark - 自定义键盘位移变化
261+ - (void )customKeyboardMove : (CGFloat)customKbY
262+ {
263+ [UIView animateWithDuration: 0.25 animations: ^{
264+ self.frame = Frame (0 ,customKbY, SCREEN_WITDTH, Height (self.frame ));
265+ }];
266+ }
267+
268+ #pragma mark - 监听输入框
269+ - (void )textViewDidChange : (UITextView *)textView
214270{
215271
216272}
273+ - (BOOL )textView : (UITextView *)textView shouldChangeTextInRange : (NSRange )range replacementText : (NSString *)text
274+ {
275+ return YES ;
276+ }
217277
218278#pragma mark - 拍摄 , 照片 ,视频按钮点击
219279- (void )handleButtonClick : (ChatHandleButton *)button
0 commit comments