您的位置:首页 > 移动开发 > IOS开发

iOS 键盘

2016-07-01 11:44 573 查看
键盘类型

typedef enum {
UIKeyboardTypeDefault,               默认键盘,支持所有字符
UIKeyboardTypeASCIICapable,          支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符
UIKeyboardTypeURL,                    URL键盘,支持.com按钮 只支持URL字符
UIKeyboardTypeNumberPad,                  数字键盘
UIKeyboardTypePhonePad,                  电话键盘
UIKeyboardTypeNamePhonePad,           电话键盘,也支持输入人名
UIKeyboardTypeEmailAddress,               用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad,                 数字键盘 有数字和小数点
UIKeyboardTypeTwitter,                优化的键盘,方便输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType;


【监控键盘的出现和隐藏】

//键盘的出现
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
//键盘的隐藏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasDismiss:) name:UIKeyboardDidHideNotification object:nil];


【键盘的高度】

//实现当键盘出现的时候计算键盘的高度大小。用于输入框显示位置
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
//kbSize为键盘尺寸
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//键盘的高度
if(kbSize.height == 216)
{
keyboardhight = 0;
}
else
{
keyboardhight = 36;   //252 - 216 系统键盘的两个不同高度
}
}

//输入结束时调用动画(把按键。背景。输入框都移下去)
-(void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@"tabtabtab");
[self endEditAnimation];

//释放
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: