views:

1319

answers:

5

I would like to show the user a splash screen (a picture) while my Cocoa-based application launches. How would this be possible?

+8  A: 

Why do you hate your users?

Seriously, don't do this. Don't make your users wait to use your app. Make your app launch quickly instead.

(And just in case you insist on an answer: Show a window with the image in it, then hide the window when you feel the user has waited long enough.)

Peter Hosey
Hmmm not all applications can launch quickly. Some need to connect to remote databases, initialize structures, etc. Showing a nonfunctioning app is worse than a splash.
Martín Marconcini
... reticulating splines ...
DrJokepu
Why not show a functioning app? Not necessarily *fully* functioning, but let the user configure prefs, add a new database to connect to, or whatever. Don't just block the UI with a splash screen.
Peter Hosey
my app is not launch quickly. so I want to show a splash , I think if you can take me some code to get this point.Thanks a lot!
jin
jin, the solution is not to show your user a picture to look at while he waits, but to make him not have to wait. Use Shark and/or Instruments to find out why your app launches slowly, then optimize it.
Peter Hosey
Peter is right. Users despise splash screens. Unless you're writing Photoshop, there's no reason your app should take more than a few seconds to launch.
Alex
Sometimes there is nothing you can do. If the Marketing department dictates a splash screen is necessary then I have to add one. Not everybody is an indy developer.Marketing may relent if users complain about it, but for my App it doesn't really slow anything down. Opening a 12MB NEF does that.
Mark Thalman
If the splash screen has useful operations it can be valuable like opening from a template (e.g. Pages, Numbers), but be flexible allow the user to opt-out of ever seeing the splash again as most apps do. It doesn't have to be a black-and-white issue...
Evan
Evan: I don't consider that a splash screen. To my mind, a splash screen is simply the product and/or company's logo, possibly with “Loading…” and/or a progress bar underneath. I call what you described a “starting points” window, as ClarisWorks called it.
Peter Hosey
A: 

First thanks a lot. because my app running for a while time , so I want to show a splash before app running . Now if I show a window inside with a image , after that how to run the app? How to make sure that the app running after the splash showing ? How to do to get the sequence ?

jin
A: 

Just put up a window with the image and close it when you are done with your launch initialization.

Mark Thalman
+5  A: 

Although Peter's answer is ultimately correct (you should rewrite your app to launch faster), sometimes that's not a practical option. For example loading code later in the application may take too long (e.g. a data acquisition application), forcing it to be loaded at startup. If you decide that you want to show a splash screen, the easiest way is to show it in the application delegate's applicationWillFinishLaunching: method. Create a splash window in your applications MainMenu.nib and add an outlet to your app delegate referencing that window. You can then put the window onscreen in applicationWillFinishLaunching: and hide it in applicationDidFinishLaunching:. Note that the main thread's NSRunLoop is not iterating during this time, so if you want to update the splash screen (with status, a progress bar, or such), you'll need to manage those redraw events yourself.

Again, think very hard about whether the long startup is necessary. If it is, showing a splash screen with a progess indicator is the minimum that you owe your users.

Barry Wark
First Thank you very much. And I show the window in applicationWillFinishLaunching method use orderFront,then hide it in applicationDidFinishLaunching: use orderOut,Now I found that the mainWindow not to show and the app terminate ,why ? How to do to resolute this question? Thanks!
jin
A: 

First Thank you very much. And I show the window in applicationWillFinishLaunching method use orderFront,then hide it in applicationDidFinishLaunching: use orderOut,Now I found that the mainWindow not to show and the app terminate ,why ? How to do to resolute this question? Thanks!

jin