ios - UIKeyboardFrameBeginUserInfoKey & UIKeyboardFrameEndUserInfoKey

标签 ios iphone keyboard

在管理键盘中 documentation :

UIKeyboardFrameBeginUserInfoKey The key for an NSValue object containing a CGRect that identifies the start frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.

UIKeyboardFrameEndUserInfoKey The key for an NSValue object containing a CGRect that identifies the end frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.

起始帧结束帧是什么意思?它们有什么区别?

最佳答案

起始帧是键盘在动画开始处的位置:如果显示键盘则在屏幕外,如果键盘隐藏则在屏幕上。结束帧是键盘在动画结束时的位置:反之亦然。您可以利用它们之间的差异编写一个方法来响应隐藏和显示键盘。

在为您的 View 更改设置动画时,还要确保使用 UIKeyboardAnimationCurveUserInfoKeyUIKeyboardAnimationDurationUserInfoKey:这样,您的动画和操作系统的动画将同步。

另一个提示:您链接到的文档指出,“userInfo 字典的 UIKeyboardFrameBeginUserInfoKey 和 UIKeyboardFrameEndUserInfoKey 属性中包含的矩形应该仅用于它包含的大小信息。不要使用矩形的原点(它总是{0.0, 0.0}) 在矩形相交操作中”。至少在 OS 3.2 的 iPad 上,这不是真的。两个矩形具有相同的大小,而屏幕坐标中的原点在两者之间不同。

您可能会发现这个问题有帮助:UIKeyboardBoundsUserInfoKey is deprecated, what to use instead?

关于ios - UIKeyboardFrameBeginUserInfoKey & UIKeyboardFrameEndUserInfoKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3332364/

相关文章:

ios - 如何本地化声音文件

ios - 从右向左移动 core plot 图

ios - UICollectionViewDelegateFlowLayout Edge Insets 未被 sizeForItemAt 函数识别?

iOS 10 ScrollView 不工作

ios - 以编程方式创建的 ImageViews 错误 "unresolved identifier"

swift - iOS 14 SwiftUI 键盘自动提升 View

Javascript keydown 操作对象

iphone - 如何改进 iOS 中的 TWTweetComposeViewController 代码?

iOS 应用程序评论 - 视频流 MPEG-DASH 时间超过 10 分钟

android - 在 Android 上滚动 ListView 后自动隐藏键盘