UITextView键盘操作

来源:互联网 发布:中电数据 医疗 编辑:程序博客网 时间:2024/05/22 01:44

UITextView常用属性设置:

textView.showsHorizontalScrollIndicator   //设置是否显示水平方式下滚动条

textView.showsVerticalScrollIndicator   //设置是否显示竖直滚动条

textView.keyboardType  //设置键盘样式(打电话用的数字键盘,发信息用的字母键盘等样式)

textView.returnKeyType  //设置return键的样式

textView.keyboardAppearance  //设置键盘显示(可以设置灰色和黑色背景键盘)

textView.autocapitalizationType //设置字母大写(单词首字母大写、句子首字母大写、全部大写等)

textView.secureTextEntry  //隐私数据输入相关,关闭自动更正


键盘弹出;

当点击UITextView时,UITextView会成为第一响应者,并自动请求系统显示键盘。


关闭键盘:

[textView resignFirstResponder];  放弃第一响应者的身份


键盘通知:

当系统显示或者隐藏键盘时,会发送对应的通知。

UIKeyboardWillShowNotification

UIKeyboardDidShowNotification

UIKeyboardWillHideNotification

UIKeyboardDidHideNotification


通常情况下,在我们需要输入信息时,会将UITextView调整到键盘上面,输入完毕时,又会将UITextView放到屏幕最下方,这时就需要来根据键盘的尺寸来调整位置。

先注册消息:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];


- (void)keyboardWillShow:(NSNotification *)notification

{

     NSDictionary *userInfo = [notification userInfo];

     NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

     CGRectMake keyboardRect = [value CGRectValue];

}

原创粉丝点击