Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a splash screen during launch of a Cocoa app?

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


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 ?


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!

like image 727
jin Avatar asked Mar 26 '09 09:03

jin


2 Answers

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.

like image 126
Barry Wark Avatar answered Sep 29 '22 11:09

Barry Wark


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.)

like image 30
Peter Hosey Avatar answered Sep 29 '22 10:09

Peter Hosey