Show splash / load screen on iPhone

I have a simple iPhone app that loads very quickly, so the splash screen is only displayed for a split second. Is there a way to control how long the splash screen is displayed? I've searched around and didn't find anything that seems to work. Should I create a subview with my splash? How can I control its display time and switch between subview and main view?

+3


source to share


4 answers


While I agree with the views expressed here and on another question about why you shouldn't "abuse" the default screen, it seems pretty trivial to me to achieve this effect:

On startup, simply create a view that looks exactly like the splash screen and use NSTimer

to cancel it. Quite easy actually.



// viewDidLoad
[self performSelector:@selector(dismiss) 
           withObject:nil 
           afterDelay:yourTimeIntervalInSectons];
// dismiss
[self performSegueWithIdentifier:@"ID" sender:nil];

      

However, do not force the splash screen every time the app becomes active. I once did this for a very specific and useful purpose in the context of my application, but Apple rejected it. Hey, they even called me Saturday night to explain it to me.

+6


source


While I agree with everything that was said here, I had to implement a timed splash screen once, so here's the code:

- (void)showSplashWithDuration:(CGFloat)duration
{
    // add splash screen subview ...

    UIImage *image          = [UIImage imageNamed:@"Default.png"];
    UIImageView *splash     = [[UIImageView alloc] initWithImage:image];
    splash.frame            = self.window.bounds;
    splash.autoresizingMask = UIViewAutoresizingNone;
    [self.window addSubview:splash];


    // block thread, so splash will be displayed for duration ...

    CGFloat fade_duration = (duration >= 0.5f) ? 0.5f : 0.0f;
    [NSThread sleepForTimeInterval:duration - fade_duration];


    // animate fade out and remove splash from superview ...

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

      

Just call the function somewhere in the AppDelegate method -applicationDidFinishLaunching:withOptions:




@ asgeo1: the code works fine for me (I have used similar code in several projects). I've added a sample project to my Dropbox for your convenience.

+5


source


Don't do this and / or don't read why here

iOS Splash Screen Duration (Default.png)

It doesn't really make sense to extend the duration of the Default.png.

+3


source


Now I totally agree with the above posts that you shouldn't be doing this, but if you still want it, it can be achieved very easily by adding the following to yours AppDelegate.m

.

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    sleep(2);
}

      

"2" means how many seconds to sleep. It will accept values ​​like ".5"

+3


source







All Articles