【发布时间】:2015-05-20 22:35:50
【问题描述】:
我需要在显示键盘时调整“消息栏”,并且在使用 iPad 模态视图控制器时遇到问题。 “消息栏”在显示时应位于键盘的正上方,然后在键盘隐藏时位于模式的底部(类似于消息应用程序样式)。
问题是我需要根据模态坐标系获得键盘框架的最高点。 我发现这个答案在理论上似乎是正确的,但不起作用(How can I find portion of my view which isn't covered by the keyboard (UIModalPresenationStyleFormSheet)?):
仅供参考当显示键盘时,主窗口中的键盘框架(即“keyboardFrame”)= (-84.0, 526.0, 768.0, 264.0)。为模态视图控制器坐标系翻译时的键盘框架(即'newSize')= (-168.0, 292.0, 768.0, 264.0)*
// Convert the keyboard rect into the view controller's coordinate system
// The fromView: nil means keyboardRect is in the main window's coordinate system
let newSize = self.view.convertRect(keyboardFrame, fromView: nil)
// And then this is the part that gets covered!
let keyboardCoveredHeight = self.view.bounds.height - newSize.origin.y
self.messageToolbar.bottomConstraint.constant = -keyboardCoveredHeight
【问题讨论】:
-
@Lefteris - 我确实使用它作为指导。如 OP 中所述,问题出在 iPad 中使用模态视图控制器时。键盘框架相对于主窗口,而不是模式。因此,为了将底部约束设置为正确的值,我需要知道键盘顶部的位置(就模态坐标系而言)。但目前这样做的方法并没有给出准确的翻译值。
-
该文档说“我们在回调中获得的键盘框架始终以纵向表示”,这在 iOS 8 中不再适用。在 iOS 8 中,旋转只是随着大小的变化而处理,因此不需要考虑设备的方向。
-
@AaronBrager 没错,但同样,这不是手头的问题。同样,问题是获得关于键盘顶部所在的模态视图控制器坐标系的“正确坐标”(显示在主窗口的坐标系中)
-
为什么不把你的 messageToolbar 作为 inputAccessoryView 呢?它将与键盘顶部对齐。
标签: ios ipad frame modalviewcontroller uikeyboard