gpt4 book ai didi

objective-c - iPad 分离式键盘

转载 作者:太空狗 更新时间:2023-10-30 03:29:31 29 4
gpt4 key购买 nike

我正在创建一个类似于 iPad 的 iMessage 应用程序的应用程序,用于发送消息。因此,当显示键盘时,消息 View 和输入附件 View 的底部锚定了一个输入 View 。此外,在停靠或未停靠时显示键盘时,必须正确调整消息 View 的大小。

我遇到的问题是来自 UIKeyboardWillChangeFrameNotification 的通知数据不一致。

首先,用户可以通过 3 种方式取消停靠键盘:

  1. 按住右下键,然后向上滑动
  2. 按住右下键,弹出菜单时,选择“取消停靠”
  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}}";
}

为什么通知数据不一样?有人找到了检测拆分键盘事件的明确方法吗?

最佳答案

没有明确的方法没有。

我在接下来的步骤中解决了这个问题:

  1. 获取当前方向。
  2. 如果方向是横向,那么我会得到 UIKeyboardFrameEndUserInfoKey 的高度。它必须等于216。这意味着键盘是拆分模式,否则不是;
  3. 如果方向是纵向,那么我会得到 UIKeyboardFrameEndUserInfoKey 的高度。它必须等于216。这意味着键盘是拆分模式,否则不是;

我更新了我的 gist for example.使用 convertRect 方法。

关于objective-c - iPad 分离式键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10749311/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com