OS X应用程序不会在Swift中按下Dock图标时启动新窗口 [英] OS X app doesn't launch new window on dock icon press in Swift

查看:43
本文介绍了OS X应用程序不会在Swift中按下Dock图标时启动新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Swift中制作Mac应用程序,遇到了问题.从终止状态启动我的应用程序时,它会自动启动一个新窗口.但是,如果用户 X 从我的应用程序中退出(带有红色的X图标)而不是退出它,然后单击了我的应用程序的应用程序图标,则不会自动打开新窗口.

I am making a Mac app in Swift, and running into a problem. When my app is first launched from the terminated state, it automatically launches a new window. But if the user Xs out of my app (with the red X icon) instead of quitting it, then hits the app icon of my app, a new window doesn't automatically open.

只要还没有打开我的应用程序窗口,我如何才能使Mac应用程序每次点击停靠图标时启动一个新窗口?

How can I make my Mac app launch a new window every time the dock icon is hit, as long as there isn't already a window of my app open?

推荐答案

将此添加到您的应用程序委托中:

Add this to your App Delegate:

func applicationShouldHandleReopen(theApplication: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
    if !flag {
        for window: AnyObject in theApplication.windows {
            window.makeKeyAndOrderFront(self)
        }
    }
    return true
}

这篇关于OS X应用程序不会在Swift中按下Dock图标时启动新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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