簡體   English   中英

從通知獲取鍵盤高度

[英]Getting keyboard height from Notification

我從帶有代碼的通知中獲取鍵盤高度

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

我用它來呈現其他視圖,它的高度與鍵盤的高度相同。 為此,我創建了臨時textField並從中抓取鍵盤高度。 我使用代碼:

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

然后我得到身高的價值。 它等於253。但是隨后我從實際textField的高度獲得了216。我需要從temp文本字段發送的通知中獲得216的值。 我怎么才能得到它?

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

我不知道您要如何調整高度,但是我不確定這是獲取鍵盤高度的最佳方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM