当按下主页按钮时,我想隐藏键盘并将我的 View 恢复到正常状态,以便当应用程序再次启动/前景时,没有选择文本字段并且键盘被隐藏。
我的应用委托(delegate)有这个方法的实现:
- (void)applicationDidEnterBackground:(UIApplication *)application {
[tabBarController.view endEditing:YES];
}
键盘确实被移除了,但我不明白的是:Apple 的文档说应用程序的快照是在方法返回之后拍摄的。但是,这会导致键盘向下滑动动画出现问题。有时,当应用程序再次启动一小会儿时,它会显示键盘处于半按下状态。我假设屏幕截图是在动画完成之前截取的。
我该怎么做才能解决这个问题,在 applicationDidEnterBackground:
方法中引入一个短计时器?我想知道是否有“更清洁”的解决方案。
最佳答案
我没有试过这个,但是在你放弃键盘之前关闭动画怎么样:
- (void)applicationDidEnterBackground:(UIApplication *)application {
[UIView setAnimationsEnabled:NO];
[tabBarController.view endEditing:YES];
}
如果这有效,您需要在 applicationWillEnterForeground 中重新打开它们
关于cocoa-touch - 在 applicationDidEnterBackground : - screenshot problem 中隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4659394/