【移动应用开发技术】怎么在iOS中实现聊天输入框功能_第1页
【移动应用开发技术】怎么在iOS中实现聊天输入框功能_第2页
【移动应用开发技术】怎么在iOS中实现聊天输入框功能_第3页
【移动应用开发技术】怎么在iOS中实现聊天输入框功能_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】怎么在iOS中实现聊天输入框功能

这篇文章将为大家详细讲解有关怎么在iOS中实现聊天输入框功能,文章内容质量较高,因此在下分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。实现方法如下:-

(void)viewDidLoad

{

[super

viewDidLoad];

self.view.backgroundColor

=

[UIColor

colorWithRed:0.92

green:0.92

blue:0.92

alpha:1.00];

self.keyView

=

[[DKSKeyboardView

alloc]

initWithFrame:CGRectMake(0,

K_Height

-

51,

K_Width,

51)];

//设置代理方法

self.keyView.delegate

=

self;

[self.view

addSubview:_keyView];

}主要就是上面的添加,此时输入框就已经添加到当前的VC中;稍后会讲到里面的代理方法的作用;工程结构如下图

主要是红色线标出的两个类,结构比较简单设置输入行数,输入框内容变化时改变输入款高度DKSKeyboardView.h中的代码如下:#import

@protocol

DKSKeyboardDelegate

@optional

//非必实现的方法

/**

点击发送时输入框内的文案

@param

textStr

文案

*/

-

(void)textViewContentText:(NSString

*)textStr;

/**

键盘的frame改变

*/

-

(void)keyboardChangeFrameWithMinY:(CGFloat)minY;

@end

@interface

DKSKeyboardView

:

UIView

@property

(nonatomic,

weak)

id

delegate;

@end关于上面的两个代理方法,由于文章篇幅问题,实现的过程可参考demo,里面有详细的注释;在DKSKeyboardView.m中,以下列出少量重要代码,主要是改变frame1、点击输入框,键盘出现//键盘将要出现

-

(void)keyboardWillShow:(NSNotification

*)notification

{

[self

removeBottomViewFromSupview];

NSDictionary

*userInfo

=

notification.userInfo;

CGRect

endFrame

=

[userInfo[UIKeyboardFrameEndUserInfoKey]

CGRectValue];

//获取键盘的高度

self.keyboardHeight

=

endFrame.size.height;

//键盘的动画时长

CGFloat

duration

=

[userInfo[UIKeyboardAnimationDurationUserInfoKey]

doubleValue];

[UIView

animateWithDuration:duration

delay:0

options:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey]

integerValue]

animations:^{

self.frame

=

CGRectMake(0,

endFrame.origin.y

-

self.backView.height

-

StatusNav_Height,

K_Width,

self.height);

[self

changeTableViewFrame];

}

completion:nil];

}2、键盘消失-

(void)keyboardWillHide:(NSNotification

*)notification

{

//如果是弹出了底部视图时

if

(self.moreClick

||

self.emojiClick)

{

return;

}

[UIView

animateWithDuration:0.25

animations:^{

self.frame

=

CGRectMake(0,

K_Height

-

StatusNav_Height

-

self.backView.height,

K_Width,

self.backView.height);

[self

changeTableViewFrame];

}];

}3、点击更多按钮-

(void)moreBtn:(UIButton

*)btn

{

self.emojiClick

=

NO;

//主要是设置表情按钮为未点击状态

if

(self.moreClick

==

NO)

{

self.moreClick

=

YES;

//回收键盘

[self.textView

resignFirstResponder];

[self.emojiView

removeFromSuperview];

self.emojiView

=

nil;

[self

addSubview:self.moreView];

//改变更多、self的frame

[UIView

animateWithDuration:0.25

animations:^{

self.moreView.frame

=

CGRectMake(0,

self.backView.height,

K_Width,

bottomHeight);

self.frame

=

CGRectMake(0,

K_Height

-

StatusNav_Height

-

self.backView.height

-

bottomHeight,

K_Width,

self.backView.height

+

bottomHeight);

[self

changeTableViewFrame];

}];

}

else

{

//再次点击更多按钮

//键盘弹起

[self.textView

becomeFirstResponder];

}

}4、改变输入框大小-

(void)changeFrame:(CGFloat)height

{

CGRect

frame

=

self.textView.frame;

frame.size.height

=

height;

self.textView.frame

=

frame;

//改变输入框的frame

//当输入框大小改变时,改变backView的frame

self.backView.frame

=

CGRectMake(0,

0,

K_Width,

height

+

(viewMargin

*

2));

self.frame

=

CGRectMake(0,

K_Height

-

self.backView.height

-

self.keyboardHeight,

K_Width,

self.backView.height);

//改变更多按钮、表情按钮的位置

self.emojiBtn.frame

=

CGRectMake(viewMargin,

self.backView.height

-

viewHeight

-

viewMargin,

viewHeight,

viewHeight);

self.moreBtn.frame

=

CGRectMake(self.textView.maxX

+

viewMargin,

self.backView.height

-

viewHeight

-

viewMargin,

viewHeight,

viewHeight);

//主要是为了改变VC的view的frame

if

(self.delegate

&&

[self.delegate

responds

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论