Showing keyboard at the right time iOS7(在正确的时间显示键盘iOS7)
问题描述
在 iOS 6 中,我习惯于在 viewDidLoad
中显示键盘.
In iOS 6 I'm used to present keyboard in viewDidLoad
.
- (void)viewDidLoad
{
[super viewDidLoad];
[txtField becomeFirstResponder];
}
这样,当navigationController推送新的viewController时,键盘已经存在,从左到右平滑动画,避免了自底向上的动画.
This way, when navigationController pushes the new viewController, keyboard is already there, animating smoothly from left to right and avoiding bottom-up animation.
在 iOS 7 中,这种行为似乎被破坏了.
In iOS 7 this behavior seems broken.
如果我在 viewDidLoad
中添加 [txtField becomeFirstResponder]
,键盘出现在推送动画的中间,已经在它的最终位置:一个不愉快的效果!!
If I add [txtField becomeFirstResponder]
in viewDidLoad
, keyboard appears in the middle of pushing animation, already in its final position: an unpleasant effect!!
我尝试在viewWillAppear
中移动[txtField becomeFirstResponder]
,但最终结果没有改变.
I've tried to move [txtField becomeFirstResponder]
in viewWillAppear
, but the final result is unchanged.
你知道一种方法来恢复 iOS 6 的行为,将新的 viewController 和键盘一起推送吗?
Do you know a way to get back iOS 6 behavior, pushing the new viewController and the keyboard all together?
使用计时器也不起作用...无论我设置什么时间延迟,键盘仅在推动动画结束时显示.
Using a timer doesn't work either... whatever time delay I set, the keyboard is shown only at the end of pushing animation.
到目前为止,我最好的尝试是将 [txtField becomeFirstResponder]
放在 viewWillLayoutSubviews
或 viewDidLayoutSubviews
中.不幸的是,在推送 viewController 时这样做有效,但在弹回时无效(键盘没有出现).
So far, my best try it is to put [txtField becomeFirstResponder]
in viewWillLayoutSubviews
or viewDidLayoutSubviews
. Unfortunately, doing so working when pushing viewController but not when popping back (the keyboard doesn't appear).
推荐答案
我已经设法在 viewWillLayoutSubviews
中推断出您的解决方法以强制它工作.
I've managed to extrapolate your workaround in viewWillLayoutSubviews
to force it to work.
- (void)viewWillLayoutSubviews {
if (![self.textField1 isFirstResponder] && ![self.textField2 isFirstResponder] && ...) {
[self.textField1 becomeFirstResponder];
}
}
这对我来说既适用于推入堆栈,也适用于关闭模态视图控制器后.
This is working for me for both pushing onto the stack, and after dismissing a modal view controller.
这篇关于在正确的时间显示键盘iOS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在正确的时间显示键盘iOS7
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01