ios UIKeyboardFrameBeginUserInfoKey 和 UIKeyboardFrameEndUserInfoKey
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3332364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIKeyboardFrameBeginUserInfoKey & UIKeyboardFrameEndUserInfoKey
提问by ohho
In the Managing the Keyboard documentation:
在管理键盘文档中:
UIKeyboardFrameBeginUserInfoKeyThe key for an NSValue object containing a CGRect that identifies the start frameof 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.
UIKeyboardFrameEndUserInfoKeyThe key for an NSValue object containing a CGRect that identifies the end frameof 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.
UIKeyboardFrameBeginUserInfoKey包含 CGRect 的 NSValue 对象的键,该对象 在屏幕坐标中标识键盘的起始帧。这些坐标不考虑由于界面方向变化而应用于窗口内容的任何旋转因素。因此,您可能需要在使用之前将矩形转换为窗口坐标(使用 convertRect:fromWindow: 方法)或查看坐标(使用 convertRect:fromView: 方法)。
UIKeyboardFrameEndUserInfoKey包含 CGRect 的 NSValue 对象的键,该对象 在屏幕坐标中标识键盘的结束帧。这些坐标不考虑由于界面方向变化而应用于窗口内容的任何旋转因素。因此,您可能需要在使用之前将矩形转换为窗口坐标(使用 convertRect:fromWindow: 方法)或查看坐标(使用 convertRect:fromView: 方法)。
What is the meaning of start frame
and end frame
? What is the difference between them?
是什么意思start frame
和end frame
?它们之间有什么区别?
回答by David M.
The start frame is where the keyboard is at the beginning of the animation: offscreen if the keyboard is being shown, or onscreen if the keyboard is being hidden. The end frame is where the keyboard will be at the end of the animation: vice versa. You can use the difference between them to write a single method that responds to both hiding and showing the keyboard.
开始帧是键盘在动画开始处的位置:如果键盘显示在屏幕外,如果键盘被隐藏,则在屏幕上。结束帧是键盘在动画结束时所在的位置:反之亦然。您可以使用它们之间的差异来编写一个方法来同时响应隐藏和显示键盘。
Be sure also to use UIKeyboardAnimationCurveUserInfoKey
and UIKeyboardAnimationDurationUserInfoKey
when animating your view changes: that way, your animations and the OS's animations will be in sync.
确保在动画视图更改时使用UIKeyboardAnimationCurveUserInfoKey
和UIKeyboardAnimationDurationUserInfoKey
:这样,您的动画和操作系统的动画将同步。
Another hint: The documentation you linked to states, "The rectangle contained in the UIKeyboardFrameBeginUserInfoKey and UIKeyboardFrameEndUserInfoKey properties of the userInfo dictionary should be used only for the size information it contains. Do not use the origin of the rectangle (which is always {0.0, 0.0}) in rectangle-intersection operations". At least on the iPad on OS 3.2, this is not true. Both rects have the same size, while the origin, which is in screen coordinates, differs between the two.
另一个提示:您链接到的文档指出,“userInfo 字典的 UIKeyboardFrameBeginUserInfoKey 和 UIKeyboardFrameEndUserInfoKey 属性中包含的矩形应仅用于其包含的大小信息。不要使用矩形的原点(始终为 {0.0, 0.0}) 在矩形相交操作中”。至少在运行 OS 3.2 的 iPad 上,情况并非如此。两个矩形的大小相同,而屏幕坐标中的原点在两者之间不同。
You may find this question helpful: UIKeyboardBoundsUserInfoKey is deprecated, what to use instead?
您可能会发现这个问题很有帮助:UIKeyboardBoundsUserInfoKey 已弃用,该使用什么代替?