views:

13164

answers:

11

How can I display a splash screen for a longer period of time than the default time on an iPhone?

+13  A: 

The simplest way to do this is to create a UIImageView who's image is your Default.png. In your applicationDidFinishLaunching: method, add that image view to your window, and hide it when you'd like your splash screen to go away.

Ben Gottlieb
+12  A: 

Read the Apple iPhone Human Interface Guidelines (HIG). The "splash screen" isn't supposed to be for branding or displaying a logo, it's supposed to look like the default condition of the app so it appears to start up quickly.

Making it stay there for longer would be a violation of the HIG.

Paul Tomblin
This doesn't answer the question at all. The questions asked is "how?", not "should I?".
korona
Sometimes "don't do it" is the best answer to "how".
Paul Tomblin
For reference I do agree that you shouldn't do this, but I still disagree with this way of answering. I'll agree to disagree ;)
korona
So, @korona, how *do* you tell somebody that what they're asking how to do is something that they really, really shouldn't do other than answering the question?
Paul Tomblin
@Paul Tomblin: I understand your point, but it really is beside the point. I think a friendly warning coupled with a "However, if you really want to do this, ..." response might be the best approach. Thoughts?
LucasTizma
No, it's not besides the point. If the question was "Where do you hide your house keys because I want to steal your stuff", would you chide me if my answer was "Don't do that!" instead of "a friendly warning coupled with a 'However..."?
Paul Tomblin
Nope, sorry Paul, the question is "how".
Justicle
Justicle, how can I kick you to inflict the most pain? Keep in mind that telling me not to do it isn't answering the question.
Paul Tomblin
Thankfully there were useful answers below. Yes, I understand the joy of feeling like a righteous purist -- but the New York Times application does something like this, and it's a wonderful way to start that app. It leads to more user delight, not less. The Apple police didn't reject that app because they know they don't have the answer to every situation -- they leave it to us developers to get creative.
Vineel Shah
+3  A: 

Make your app take longer to load.

In all seriousness, Paul Tomblin is correct that this usually isn't a good idea. Default.png is a mechanism intended to make your app appear to load faster by holding an "empty" screenshot. Using it for a splash screen is a minor abuse, but intentionally making that splash screen appear for longer than it needs to is almost sick. (It will also degrade your user experience. Remember, every second the splash screen is visible is a second that the user is impatiently staring at your logo, swearing they'll switch to the first decent competitor they can find.)

If you're trying to cover for some sort of secondary loading--for example, if the interface has loaded and you're just waiting to get some data from the network--then it's probably okay, and Ben Gottlieb's approach is fine. I'd suggest adding a progress bar or spinner to make it clear to the user that something really is going on.

Brent Royal-Gordon
I don't agree that intentionally delaying the loading of the app for branding is necessarily "sick." Keeping a logo up there for 1 extra second, for example, seems entirely appropriate. However, it would be a bit ridiculous to delay the app for an significant amount of time just for branding purposes.
LucasTizma
+3  A: 

Write an actual splash screen class.

Here's a freely usable splash screen that I recently posted in my iPhone in Action blog: http://iphoneinaction.manning.com/iphone_in_action/2009/03/creating-a-splash-screen-part-one.html

Shannon A.
+6  A: 

I needed to do this to block showing a table view until the data was loaded over the network. I used a variation of one I found here:

http://michael.burford.net/2008/11/fading-defaultpng-when-iphone-app.html

In the interface of your App Delegate:


@interface AppDelegate : NSObject 
{
  UIImageView *splashView;
}

In the implementation:


@implementation AppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {


  // After this line: [window addSubview:tabBarController.view];

  splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
  splashView.image = [UIImage imageNamed:@"Default.png"];
  [window addSubview:splashView];
  [window bringSubviewToFront:splashView];

  // Do your time consuming setup

  [splashView removeFromSuperview];
  [splashView release];
}

Make sure you have a Default.png in the resources

nevan
+1  A: 

For stylish splash screen tutorial check out this http://adeem.me/blog/2009/06/22/creating-splash-screen-tutorial-for-iphone/

Adeem Maqsood Basraa
+1  A: 

Here is my simple splash screen code. 'splashView' is an outlet for a view that contains an image logo, UIActivityIndicator, and a "Load.." label (added to my 'MainWIndow.xib' in IB). The activity indicator is set to 'animating' in IB, I then spawn a separate thread to load the data. When done, I remove the splashView and add my normal application view:

-(void)applicationDidFinishLaunching:(UIApplication *)application {
    [window addSubview:splashView];
    [NSThread detachNewThreadSelector:@selector(getInitialData:) 
                                 toTarget:self withObject:nil];
}

-(void)getInitialData:(id)obj {
    [NSThread sleepForTimeInterval:3.0]; // simulate waiting for server response
    [splashView removeFromSuperview];
    [window addSubview:tabBarController.view];
}
wcochran
A: 

simply use sleep(time in seconds); in your applicationDidFinishedLaunching method

Rahul Vyas
+2  A: 

I did it pretty simply, by having my rootViewController push a modalViewController, loading from "Splash.nib" in a subclass of UIViewController I called "SplashViewController". The exact call was:

- (void) viewDidLoad {
SplashViewController *splashScreen = [[[SplashViewController alloc]    
        initWithNibName:@"SplashViewController" bundle:nil] autorelease];
[self presentModalViewController:splashScreen animated:NO];
//continue loading while MVC is over top...

When you launch the app, it pops right up, like a splash screen should. Then, the SplashViewController nib is just a full-screen UIImageView with a splash png, 320x480. After a 1-second NSTimer (anything more did seem to get in the way), it fires timerFireMethod, a custom method that just calls

[self dismissModalViewControllerAnimated:YES];

Then the modal VC just slides down and away, leaving my top tableView. The nice thing is, while the MVC is up, the underlying table can continue to load due to the independent nature of modal view controllers. So, I don't think this violates the HIGs, and actually does allow for faster launching. What would you rather look at, a cute picture, or an empty default view (snore)?

jimiHendrix
A: 

I agree it can make sense to have a splash screen when an app starts - especially if it needs to get some data from a web site first.

As far as following Apple HIG - take a look at the (MobileMe) iDisk app; until you register your member details the app shows a typical uitableview Default.png before very quickly showing a fullscreen view.

petert
A: 

To jleedev Your code is what I have been looking for, of course I want the pages to load wile the splash screen is showned. Sorry to say Im new to iPhone programing and have a hard time getting it to work.

Could you please explane a little more on how to get your code to work. What do I have to do?

Im using phonegap to build with.

Claes Gustavsson