关于iPad键盘高度变更的通知

发布于 2024-11-30 07:18:12 字数 200 浏览 0 评论 0原文

我正在尝试在 iPad 键盘顶部显示 UITextField。

当通知出现时,我能够获得键盘的高度。

然而,在iPad中,通过更改键盘的语言输入->最有可能的是日语,键盘的高度发生了变化,因为键盘顶部显示了一个文本假设区域,这导致我的 UITextfield 被该区域隐藏......

有谁知道我如何获得高度更改通知或任何其他方式?

I am trying to show a UITextField on top of the iPad keyboard.

I was able to get the height of the keyboard when it was presented with the notification.

However, in iPad, by change the language input of the keyboard -> most likely to Japanese, the height of the keyboard changed because a text-hypothesis area was shown on top of the keyboard, that caused my UITextfield hidden by that area....

Does anybody know how can I get the height changed notification or any other way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眸中客 2024-12-07 07:18:12

答案是,当您切换语言时,每次更改都会触发 UIKeyboardDidShowNotification ,因此您始终可以获得更新的高度。

请在此处查看我的答案,了解如何设置对显示和隐藏以及获取的响应高度。

The answer is that when you switch languages, the UIKeyboardDidShowNotification fires for each change, so you always get the updated height.

See my answer here on how to set up responses to the showing and hiding, and getting the height.

染年凉城似染瑾 2024-12-07 07:18:12

Swift

UIKeyboardDidShowNotification 将不再触发键盘尺寸更改。

使用 UIKeyboardWillChangeFrameNotification 代替:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(instance.keyboardWillChange(_:)), name:UIKeyboardWillChangeFrameNotification, object: nil)

在函数中:

let targetSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() 

重要: 当键盘打开和隐藏时,此事件也会被触发,可以替换 UIKeyboardWillShowNotificationUIKeyboardWillHideNotification 如果只需要尺寸

Swift

The UIKeyboardDidShowNotification won't fire anymore the keyboard size change.

Use UIKeyboardWillChangeFrameNotification instead:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(instance.keyboardWillChange(_:)), name:UIKeyboardWillChangeFrameNotification, object: nil)

at the function:

let targetSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() 

Important: this event will be fired also when keyboard will open and will hide, can replace both UIKeyboardWillShowNotification and UIKeyboardWillHideNotification if only sizes are needed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文