在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!