Question

Long story short, I'm trying to change my iOS app's rootViewController on applicationWillEnterForeground:, like so:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    MyViewController *controller = [[MyViewController alloc] init];
    self.window.rootViewController = controller;
}

However, when iOS performs the "zoom in" animation that is performed when an app is moved from the background to the foreground, it still shows the previous rootViewController's view. Then, as soon as the animation is complete, the app blasts the new rootViewController's view onto the screen.

One way to solve this is to simply move that code to - (void)applicationDidEnterBackground:, but the problem with this solution is that, in my app, there is no way to tell if a new rootViewController will be assigned until - (void)applicationWillEnterForeground:(UIApplication *)application (it is based on time passed since leaving the app).

How can I force the app to redraw before iOS performs the animation taking the app from the background to the foreground?

Was it helpful?

Solution

I believe this is not possible. The screen that iOS shows of your app when it comes into the foreground is actually a screenshot the system took when the app went into the background. There is no way to manipulate or replace that image at the time the app comes back into the foreground.

This behavior is partly documented in the Moving to the Background section of the iOS Application Programming Guide:

Apps can use their applicationDidEnterBackground: method to prepare for moving to the background state. When moving to the background, all apps should do the following:

  • Prepare to have their picture taken. When the applicationDidEnterBackground: method returns, the system takes a picture of your app’s user interface and uses the resulting image for transition animations. If any views in your interface contain sensitive information, you should hide or modify those views before the applicationDidEnterBackground: method returns.

Apple does not explicitly document that you cannot modify or replace this screenshot at a later time but neither do they say the opposite anywhere I know of.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top