Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios fade out splash screen (iphone 5 friendly)

I'm wanting to spoof the feel of the main splash screen fading out whenever applicationDidBecomeActive is called, but it's not working. What am I doing wrong?

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if(IS_IPHONE_5)
        splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-568h.png"]];
    else
        splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];

    [self.window.rootViewController.view addSubview:splash];

    [UIView animateWithDuration:0.5 
                     animations:^{
                         splash.alpha = 0;
                     }
                     completion:^(BOOL finished) {
                         [splash removeFromSuperview];
                     }];
}

Then you need to define the following somewhere. I use the project .pch but you can use your header if you want.

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
like image 769
Jacksonkr Avatar asked Feb 07 '12 21:02

Jacksonkr


3 Answers

I find, from ios6 you get a nice transition doing this

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [UIView animateWithDuration:0.2
                          delay:0
                        options: UIViewAnimationCurveEaseIn
                     animations:^{
                        self.window.viewForBaselineLayout.alpha = 0; // and at this alpha
                     }
                     completion:^(BOOL finished){
                     }];

    return YES;
}

then immediately at the start of

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    [UIView animateWithDuration:0.5
                          delay:0
                          options: UIViewAnimationCurveEaseOut
                      animations:^{
                         self.window.viewForBaselineLayout.alpha = 1; // and at this alpha
                     }
                     completion:^(BOOL finished){
                     }];

It gives a cross fadeish effect from the loading screen to the now loaded app screen.

like image 121
Aardvark Avatar answered Nov 01 '22 00:11

Aardvark


If that is really your code, you probably have a typo in the image name. (If not, let us know what "not working" means.)

Also, the splash screen doesn't normally come up every applicationDidBecomeActive:. didFinishLaunchingWithOptions: is the time you know that you have been launched and the splash screen had been shown on your behalf.

like image 32
David Dunham Avatar answered Oct 31 '22 23:10

David Dunham


Try adding it directly to your window instead of the rootViewController.view.

[self.window addSubview:splash];

You may also need to rotate the image using view.transform to align with the startup image.

like image 3
Nick Lockwood Avatar answered Nov 01 '22 01:11

Nick Lockwood