如何在启动Cocoa应用程序时显示启动屏幕? [英] How to show a splash screen during launch of a Cocoa app?

查看:125
本文介绍了如何在启动Cocoa应用程序时显示启动屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的基于Cocoa的应用程序启动时向用户显示启动屏幕(图片)。这是怎么可能的?

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 ?

首先非常感谢。我在applicationWillFinishLaunching方法中使用orderFront显示窗口,然后隐藏它在applicationDidFinishLaunching:使用orderOut,现在我发现mainWindow不显示和应用程序终止,为什么?如何解决这个问题?谢谢!

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!

推荐答案

虽然彼得的答案最终是正确的(你应该重写应用程序以更快地启动) ,有时这不是一个实用的选择。例如,稍后在应用中加载代码可能花费太长时间(例如,数据获取应用),迫使其在启动时加载。如果你决定要显示一个初始屏幕,最简单的方法是在应用程序委托的 applicationWillFinishLaunching:方法中显示它。在应用程序MainMenu.nib中创建一个启动窗口,并向您的应用程序委托添加引用该窗口的插座。然后可以在 applicationWillFinishLaunching:中将窗口放在屏幕上,并将其隐藏在 applicationDidFinishLaunching:中。注意,主线程的NSRunLoop在这段时间内不会迭代,所以如果你想更新启动屏幕(状态,进度条等),你需要自己管理这些重绘事件。

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.

这篇关于如何在启动Cocoa应用程序时显示启动屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆