有没有人找到使用新 iOS5 键盘事件的好方法? [英] Has anyone found a good way of using the new iOS5 keyboard events?

查看:18
本文介绍了有没有人找到使用新 iOS5 键盘事件的好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为我的 iPad 应用程序开发最近的一项功能期间,我意识到新的 iOS5 键盘停靠/拆分行为导致了巨大的问题.我使用 inputAccessoryView 作为键盘,上面有一个文本字段,类似于 Safari 的在页面上查找功能.我在可滚动的 UIWebView 上显示键盘,所以我的部分麻烦来自于键盘停靠时 UIWebview 缩小,而键盘未停靠时(主要是)全屏 webview.

During development of a recent feature for my iPad app, I realized that the new iOS5 keyboard docking/splitting behavior was causing huge issues. I use an inputAccessoryView for the keyboard with a text field on it similar to Safari's find on page feature. I display the keyboard over a scrollable UIWebView, so part my troubles come from having a shrunken UIWebview when the keyboard is docked and having a (mostly) fullscreen webview when it is undocked.

我在使用 API 时遇到的主要问题是,新的 UIKeyboardWillChangeFrameNotification 和 UIKeyboardDidChangeFrameNotification 通知充其量是从以前的 API 退后一步,并且有垃圾数据,几乎无法理解键盘在做什么很多情况.

The main issues I have run into with the API are that the new UIKeyboardWillChangeFrameNotification and UIKeyboardDidChangeFrameNotification notifications are a step back from the previous API at best, and have garbage data that makes it nearly impossible to understand what the keyboard is really doing in many cases.

是否可以在不仔细检查通知中返回的开始/结束帧的情况下识别以下任何键盘行为?

Can any of the following keyboard behaviors be recognized without arduously examining the begin/end frames that come back on the notifications?

  • 键盘断开连接
  • 键盘底座
  • 键盘拆分/未拆分
  • 未停靠的键盘显示
  • 未停靠的键盘隐藏
  • 键盘未停靠时视图会旋转

我想出了一些抽象来识别停靠或屏幕外的帧,但即便如此,我的代码也变得非常难以管理.如果您找到了更好的方法来做到这一点,请回答或发表评论.我希望我在这里遗漏了一些东西.谢谢.

I've come up with some abstractions to recognize frames that are docked or offscreen, but even with that, my code is becoming very unmanageable. If you've found better ways to do this, please answer or comment. I hope I'm missing something here. Thanks.

推荐答案

问题是不要想太多.任何重要的事情都没有改变.如果键盘进入屏幕底部的停靠位置,您将收到显示"通知.如果它离开屏幕底部的停靠位置,您将收到隐藏"通知.这正是 iOS 5 之前发生的事情.

The thing is not to overthink this. Nothing of any importance has changed. If the keyboard comes into docked position at the bottom of the screen, you will get a "show" notification. If it leaves the docked position at the bottom of the screen, you will get a "hide" notification. That's exactly what happened before iOS 5.

唯一的区别是,它不是因为它移出屏幕而离开停靠位置,而是因为用户取消停靠而离开停靠位置.您仍然会得到隐藏",因此您可以将界面移回其基本位置.您不需要知道键盘现在已断开连接(尽管您可以通过 UIKeyboardDidChangeFrameNotification 发现它不在屏幕外,如果您真的想要的话).您不需要知道的原因是,当键盘脱离/拆分时,如果键盘挡住了需要看到的东西,用户可以主动移动键盘.

The only difference is that instead of leaving the docked position because it is moving offscreen, it might be leaving the docked position because the user undocked it. You'll still get a "hide", so you can move your interface back into its base position. You don't need to know that the keyboard is now undocked (though you can find out that it is not offscreen from UIKeyboardDidChangeFrameNotification if you really want to). The reason you don't need to know is that when the keyboard is undocked / split, the user can be proactive and move the keyboard if it's in the way of something that needs to be seen.

因此,您在 iOS 5 之前的所有旧代码都可以继续正常工作.这一切真的很聪明...

Thus, all your old code from before iOS 5 continues to work just fine. It's all really quite clever...

这篇关于有没有人找到使用新 iOS5 键盘事件的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆