隐藏键盘applicationDidEnterBackground: - 截图问题 [英] Hide keyboard in applicationDidEnterBackground: - screenshot problem

查看:163
本文介绍了隐藏键盘applicationDidEnterBackground: - 截图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在home键被pressed我要隐藏键盘,恢复我的看法,以一个正常的状态,这样,当应用程序被启动/重新前景化,没有被选择文本框和键盘是隐藏的。

When the home button gets pressed I want to hide the keyboard and restore my view to a sane state, so that when the app is started/foregrounded again, there is no textfield selected and the keyboard is hidden.

我的应用程序委托有这样的方法实现:

My app delegate has this implementation of the method:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [tabBarController.view endEditing:YES];
}

键盘确实得到去除,但我不明白的是这样的:苹果的文件说,该应用程序的快照拍摄的之后的方法返回。然而,这带来了用键盘滑动向下的动画的问题。有时,当应用程序再次启动了片刻它显示了键盘中途下来。我以为结束了之前的动画截图取。

The keyboard does indeed get removed, but what I don't get is this: Apple's docs say that a snapshot of the app is taken after the method returns. However this poses a problem with the keyboard slide-down animation. Sometimes when the app is started again for a short moment it shows the keyboard half-way down. I assume the screenshot is taken before the animation was finished.

我会怎么做来解决这个问题,介绍了 applicationDidEnterBackground很短的计时器:的方法?我不知道是否有一个干净的解决方案。

What would I do to solve this, introduce a short timer in the applicationDidEnterBackground: method? I wonder if there is a "cleaner" solution.

推荐答案

我还没有试过,但怎么样开启动画关闭你辞职键盘之前:

I've not tried this but what about turning animations off just before you resign the keyboard:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [UIView setAnimationsEnabled:NO];
     [tabBarController.view endEditing:YES];
}

如果这个工程需要在把他们背在applicationWillEnterForeground:中

If this works you need to turn them back on in applicationWillEnterForeground

这篇关于隐藏键盘applicationDidEnterBackground: - 截图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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