如何从OS X故事板开始隐藏初始窗口 [英] How to hide the initial window on start with OS X storyboards
问题描述
我正在创建OS X状态栏应用程序,因此我希望该应用程序开始隐藏.
I am creating an OS X status bar application, so I want the application to start hidden.
我创建了一个故事板"应用程序,并且始终选中初始窗口,即使未选中启动时可见"(默认情况下也未选中).
I have created a "storyboard" application, and the initial window always shows up, even if "Visible at launch" is unchecked (was unchecked by default).
注意:如果我禁用"是初始控制器",则该应用将正确启动,没有任何窗口,但是我的(现在是孤立的)窗口似乎永远不会添加到故事板上:
Note: if I disable "Is initial controller" then the app correctly starts without any window, but my (now orphan) window seems to never be added to the storyboard:
var mainWindow = NSStoryboard(name: "Main", bundle: nil)?.instantiateControllerWithIdentifier("mainWindow")
找不到"mainWindow"控制器(即使我在窗口控制器上正确设置了"Storyboard ID").
The "mainWindow" controller is not found (even though I correctly set "Storyboard ID" on the Window Controller).
所以我认为最好保留"是初始控制器",而只需在开始时将主窗口隐藏起来即可.
So I think it's better to leave "Is initial controller" but simply have the main window hidden at the start…
推荐答案
这可能有点hack,但是您可以这样做
This might be a bit of a hack, but you can do this
func applicationDidFinishLaunching(notification: NSNotification) {
// Insert code here to initialize your application
NSApplication.sharedApplication().windows.last!.close()
}
然后再...
NSApplication.sharedApplication().windows.last!.makeKeyAndOrderFront(nil)
NSApplication.sharedApplication().activateIgnoringOtherApps(true)
这篇关于如何从OS X故事板开始隐藏初始窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!