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

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

问题描述

在开发我的iPad应用程序的最新功能期间,我意识到新的iOS5键盘对接/拆分行为导致了巨大的问题。我使用inputAccessoryView作为键盘,其上有一个文本字段,类似于Safari的页面搜索功能。我在可滚动的UIWebView上显示键盘,所以我的麻烦来自于当键盘停靠时缩小的UIWebview并且在取消停靠时具有(大部分)全屏webview。



<我遇到的主要问题是,新的UIKeyboardWillChangeFrameNotification和UIKeyboardDidChangeFrameNotification通知最多只是从之前的API退一步,并且有垃圾数据使得几乎无法理解键盘在许多方面的作用案例。



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




  • 键盘解除锁定

  • 键盘码头

  • 键盘拆分/未拆分

  • 未锁定的键盘显示

  • 未锁定的键盘隐藏

  • 键盘取消停靠时视图旋转



我想出了一些ab用于识别停靠或离屏的帧的线索,但即便如此,我的代码变得非常难以管理。如果您找到了更好的方法,请回答或评论。我希望我在这里遗漏一些东西。谢谢。

解决方案

事情不是要过度思考这个问题。没有任何重要性发生了变化。如果键盘进入屏幕底部的停靠位置,您将收到显示通知。如果它离开屏幕底部的停靠位置,您将收到隐藏通知。这正是在iOS 5之前发生的事情。



唯一的区别是,由于它在屏幕外移动而不是离开停靠位置,它可能会离开停靠位置,因为用户脱掉它。你仍然会得到一个隐藏,所以你可以将你的界面移回其基本位置。你不需要知道键盘现在是未对接的(尽管如果你真的想要,你可以发现它不是UIKeyboardDidChangeFrameNotification的屏幕外)。您不需要知道的原因是当键盘未对接/拆分时,用户可以主动并移动键盘,如果它与需要看到的东西一样。



因此,iOS 5之前的所有旧代码都能继续正常工作。这一切都非常聪明......


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.

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?

  • Keyboard Undocks
  • Keyboard Docks
  • Keyboard Splits/Unsplits
  • Undocked Keyboard Shows
  • Undocked Keyboard Hides
  • View rotates while keyboard is undocked

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.

解决方案

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.

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.

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

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

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