在iOS7正确的时间显示键盘 [英] Showing keyboard at the right time iOS7

查看:88
本文介绍了在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!!

我试图在 [txtField becomeFirstResponder] > viewWillAppear ,但最终结果没有变化。

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.

到目前为止,我最好的尝试是在<$ c $中放入 [txtField becomeFirstResponder] c> 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正确的时间显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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