如何使 UIKeyboard 显示为视图的一部分?
邮件、联系人和短信等 Apple 应用程序使 UIKeyboard 显示为视图的一部分。 UIKeyboard 随视图滑入,而不是显示为单独的动画。我尝试在不同的地方重新创建相同的行为,例如 viewWillAppear:animated
、viewDidLoad
、loadView
code>, navigationController:willShowViewController:animated:
但没有任何效果。
我在一篇文章中读到(现在找不到该文章),当您希望 UIKeyboard 与 UITableView 一起出现时,这似乎不可能做到。然而,这个结论似乎与苹果应用程序不一致。有人可以确认吗?
有解决办法吗?
Apple apps like Mail, Contacts, and SMS make the UIKeyboard appear as part of the view. The UIKeyboard slides in with the view instead of appearing as a separate animation. I have tried to recreate the same behavior calling [myTextField becomeFirstResponder]
in different places like viewWillAppear:animated
, viewDidLoad
, loadView
, navigationController:willShowViewController:animated:
but nothing works.
I read in a post (couldn't find the post now) that this seems impossible to do when you want the UIKeyboard to appear with an UITableView. However, this conclusion seems inconsistent with the Apple apps. Can someone confirm?
Is there a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在为哪个 SDK 构建?我可能是错的,但我认为苹果说了一些关于改进在屏幕上推送视图控制器的行为以及其他动画的行为的内容。
无论如何,我通过在
viewWillAppear:
中的 UISearchBar 实例上调用becomeFirstResponder
来在我的项目中实现此功能。我正在针对 3.1 SDK 进行构建。Which SDK are you building for? I might be wrong, but I thought Apple said something about improving the behavior of pushing view controllers onscreen and the behavior of other animations.
For what it's worth, I've got this working on my project by calling
becomeFirstResponder
on my UISearchBar instance inviewWillAppear:
. I'm building against the 3.1 SDK.我们 iPhone 开发人员可能使用的键盘出现在自己的
UIWindow
中,因此无论您在应用程序中进行哪种视图操作,它总是会从底部向上滑动。苹果应用程序显然可以访问我们可能(尚未)使用的键盘的增强功能。
The keyboard as we iPhone Devs may use it appears in its own
UIWindow
, so it will always slide up from the bottom, no matter which view-acrobatics you make in your app.The Apple Apps obviously have access to enhanced functionality of the keyboard which we may not (yet) use.
当您收到 UIKeyboardWillShowNotification 通知时,您可以通过调整动画块中的视图帧大小来模仿此功能。假设您的视图底部有一个文本字段视图,就像短信应用程序首次显示短信对话时所具有的那样。当您的文本字段被点击时,UIKeyboardWillShowNotification 被触发,此时您可以像这样为该视图设置动画:
然后,如果收到 UIKeyboardWillHideNotification 通知,您可以重置视图框架。
我没有弄清楚这里框架的确切位置,所以你必须自己计算,但这应该给你基本的想法。只需考虑您希望视图帧在动画之后的位置,然后将帧设置在动画块内(即 -beginAnimations、-commitAnimations)。
此致。
You can mimic this functionality by resizing your view frames in an animation block when you get a UIKeyboardWillShowNotification notification. Say you have a text field view in the bottom of your view like the SMS app has when it first displays an SMS conversation. When your text field gets a tap, the UIKeyboardWillShowNotification gets triggered at which point you can animate that view like this:
You can then reset your view frames if you get a UIKeyboardWillHideNotification notification.
I didn't figure out the exact positions of the frames here, so you'll have to calculate that yourself, but this should give you the basic idea. Just think in terms of where you want your view frames to be after the animations and just set the frames inside an animation block (i.e. -beginAnimations, -commitAnimations).
Best regards.
它不是 Apple SDK 的私有功能。
在 iOS 7(或之前的任何其他版本)中,您可以在 loadView、viewDidLoad 或 viewWillAppear 中做一个简单的事情,
在这种情况下,您将离开-键盘向右外观与推动视图控制器的运动对齐。请注意,至少在 iOS 7 中,任何对 becomeFirstResponder 的直接调用都会提供从底部开始的标准动画。
It is not the private feature of Apple SDK.
In iOS 7 (or any other version before) you can make a simple thing in loadView, viewDidLoad or viewWillAppear
In this case you will get left-to-right appearance of the keyboard aligned with the motion of pushing view controller. Note that any direct call of becomeFirstResponder gives the standard animation from bottom at least in iOS 7.