从通知中获取键盘高度

时间:2015-09-08 13:26:17

标签: ios iphone keyboard uitextfield uikeyboard

我通过代码

从通知获得键盘高度
  CGFloat height = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].height;

我用它来呈现一些其他View,它的高度与键盘的高度相同。 为此我创建临时textField并从中获取键盘高度。我使用代码:

 UITextField *tempTextField = [[UITextField alloc]init];
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:tempTextField];
[tempTextField becomeFirstResponder];
[tempTextField resignFirstResponder];
[tempTextField removeFromSuperview];

然后我得到身高的价值。它等于253.但是我从真正的textField获得216的高度。我需要在临时文本字段发送的通知中获得216值。我怎么能得到它?

1 个答案:

答案 0 :(得分:0)

216是没有QuickType的键盘内置iOS的高度。 253就是它。

因此,在您的情况下,您必须将autocorrectionType设置为no。

UITextField *tempTextField = [[UITextField alloc]init];
tempTextField.autocorrectionType = UITextAutocorrectionTypeNo;
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:tempTextField];
[tempTextField becomeFirstResponder];
[tempTextField resignFirstResponder];
[tempTextField removeFromSuperview];

我不知道你要对高度做什么,但我不能确定这是获得键盘高度的最佳方法。

相关问题