Splash screen on resume in Iphone

随声附和 提交于 2019-12-19 05:01:43

问题


I want to add splash screen on my app when the app is resumed from the background.Is this possible? Thanks in advance


回答1:


You can update your view stack in -[UIApplicationDelegate applicationWillResignActive:].

The changes will be visible when the app resumes, and you can remove the splash screen again in -[UIApplicationDelegate applicationDidBecomeActive:].




回答2:


Some code to go along with Morten's answer. I also want to note that this does not behave properly in the simulator, but does when you run it on the device. The simulator shows a black screen until removeFromSuperview is called.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // We don't want to show a splash screen if the application is in UIApplicationStateInactive (lock/power button press)
    if (application.applicationState == UIApplicationStateBackground) {
        UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"splashimage.png"]];
        splash.frame = self.window.bounds;
        [self.window addSubview:splash];
    }

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Make sure you do not remove the last view in the event something odd happens
    if ([[self.window subviews] count] > 1) {
        // Not recommended by Apple, but client gets what client wants
        [NSThread sleepForTimeInterval:1.0];
        [[[self.window subviews] lastObject] removeFromSuperview];
    }
}

Note, I used applicationDidEnterBackground instead of applicationWillResignActive because applicationState helps to differentiate between "pressed home button" and "pressed lock/power button". UIApplicationStateBackground = "pressed home button".



来源:https://stackoverflow.com/questions/6622762/splash-screen-on-resume-in-iphone

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