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

后端 未结 4 1379
忘了有多久
忘了有多久 2020-12-13 22:49

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

4条回答
  •  天命终不由人
    2020-12-13 23:01

    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.

提交回复
热议问题