Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth transition from launch image to main view

Is it possible to implement a smooth transition when the app loads, from the launch image to the first view?

The default behavior is on/off, with an immediate change: the launch image appears, then it instantaneously disappears to let the main view controller take place. I'd like to implement some fading or zooming in or out.

Is this possible?

Thank you!

like image 629
marzapower Avatar asked Jun 10 '11 17:06

marzapower


2 Answers

There's no framework support, but you can get that result if you do it yourself, manually. Depending on what your launch image is, and what your UI looks like, you can do it in different ways, but basically: make your first view controller load and display your default.png image in an image view when it loads up. Then animate a fade out of that image to reveal your actual UI.

like image 81
Ben Zotto Avatar answered Oct 02 '22 16:10

Ben Zotto


Modified Dancreek's answer to do it all in AppDelegate application:didFinishLaunchingWithOptions. I like this because the code is guaranteed to only run at app start, and it's not polluting any of the view controllers.

It's very simple:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // set up your root view and stuff....

    //.....(do whatever else you need to do)...

    // show the main window, overlay with splash screen + alpha dissolve...

        UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
    [self.window addSubview:splashScreen];        
    [self.window makeKeyAndVisible];

    [UIView animateWithDuration:0.3 animations:^{splashScreen.alpha = 0.0;}
                     completion:(void (^)(BOOL)) ^{
                             [splashScreen removeFromSuperview];
                     }
    ];
}
like image 41
n13 Avatar answered Oct 02 '22 16:10

n13