Hide keyboard in applicationDidEnterBackground: - screenshot problem

筅森魡賤 提交于 2020-01-02 08:31:14

问题


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.

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


回答1:


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];
}

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



来源:https://stackoverflow.com/questions/4659394/hide-keyboard-in-applicationdidenterbackground-screenshot-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!