2015-09-08 48 views
0

我从通知让键盘高度的代码获取键盘高度,从通知

CGFloat height = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].height; 

我用它展示了其他一些视图和它的高度一样的键盘的高度。 为此,我创建临时文本字段并从中获取键盘高度。我使用代码:

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

然后我得到身高值。它等于253.但是,我从真正的textField获得了高度216。我需要从temp textfield发送的通知中获得216值。我怎么才能得到它?

+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]; 

我不知道你正在尝试用高度来完成,但我不能确定这是获得键盘的高度的最佳方式。

+0

谢谢,它的工作原理。在我的自定义视图出现将其设置为键盘高度之前,我需要获得键盘的高度 –