我正在创建一个类似于 iPad 的 iMessage 应用程序的应用程序,用于发送消息。因此,当显示键盘时,有一个输入视图锚定在消息视图和输入附件视图的底部。此外,当键盘在停靠或脱离停靠时显示时,必须正确调整消息视图的大小。
我遇到的问题是来自 UIKeyboardWillChangeFrameNotification 的通知数据不一致。
首先,用户可以通过 3 种方式取消键盘连接:
- 按住右下键,然后向上滑动
- 按住右下键,弹出菜单时选择“取消停靠”
- 按住右下键,弹出菜单时选择“分割”
对于情况 #1,来自 UIKeyboardWillChangeFrameNotification 的通知数据是一致的。这是数据:
userInfo = {
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
}
对于情况 #2 和 #3,数据不一致,这是我收到的:
userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 0;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {384, 872}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {384, 1136}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
UIKeyboardFrameChangedByUserInteraction = 0;
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, -264}, {768, 304}}";
}
这里奇怪的是,当我在情况 #2 或 #3 下监听 UIKeyboardDidChangeFrameNotification 时,数据按预期输入:
userInfo = {
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
}
为什么通知数据不同?有人找到了检测拆分键盘事件的明确方法吗?