macOSSwiftTips

Swift语言 OS X程序中点击dock图标重新弹出窗口方法

2015-07-11  本文已影响675人  lfb_CD

最近在做一个好玩的OSX上的软件,欢迎关注我微博哦
http://weibo.com/lfbWb

本文在csdn博客地址:http://blog.csdn.net/li962429707/article/details/46837405

方法一:

func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows
flag: Bool) -> Bool {
    if !flag{
        let sb = NSStoryboard(name: "Main", bundle: nil)
        let controller = sb?.instantiateInitialController() as
NSWindowController
        controller.window?.makeKeyAndOrderFront(self)
        self.window = controller.window
    }
    return true 
}

方法二:

func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows
    flag: Bool) -> Bool {
        if !flag{
            for window in sender.windows{
                if let w = window as? NSWindow{
                    w.makeKeyAndOrderFront(self)
                }
            }
     }
    return true 
}

方法三:

var mainWindow: NSWindow!
func applicationDidFinishLaunching(aNotification: NSNotification) {
        mainWindow = NSApplication.sharedApplication().windows[0] as! NSWindow
}
func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows
    flag: Bool) -> Bool {
        if !flag{
            mainWindow.makeKeyAndOrderFront(nil)
        }
    return true 
}
上一篇下一篇

猜你喜欢

热点阅读