简体   繁体   English

Mac OS X Dock:如何使用应用程序的主图标以编程方式最大化我的应用程序,而不是最小化图标?

[英]Mac OS X Dock: How to programmatically maximize my application with the application's main icon, and not the minimized icon?

According to Mac Dock documentation : "The Dock keeps applications on its left side, while Stacks and minimized windows are kept on its right. If you look closely, you'll see a vertical separator line that separates them." 根据Mac Dock 文档 :“Dock将应用程序保留在其左侧,而Stacks和最小化的窗口保持在其右侧。如果仔细观察,您将看到一条垂直分隔线将它们分开。”

Meaning, once the application is minimized, you have a NEW dock icon in the right side, and you need to click on it in order to maximize your application. 这意味着,一旦应用程序最小化,您在右侧有一个新的停靠图标,您需要单击它以最大化您的应用程序。

However, applications like Chrome and Finder behave differently: if you click on the the LEFT icon (the "main" application's icon), it will also maximize the application! 但是,Chrome和Finder等应用程序的行为有所不同:如果单击LEFT图标(“主”应用程序的图标),它也将最大化应用程序!

I have created my own mac application, and I'd like to make it behave like Chrome: meaning once it is minimized, if you click on either the left or right dock icons, it will maximize. 我已经创建了自己的mac应用程序,我想让它像Chrome一样:意味着一旦它被最小化,如果你点击左侧或右侧的停靠栏图标,它将最大化。 How can I do that programmatically ? 我该如何以编程方式执行此操作?

[I am attaching a dock screenshot. [我附加了一个码头截图。 You can see both Chrome "main" icon and "minimized" icon next to it. 您可以在旁边看到Chrome“主”图标和“最小化”图标。 Both icons will respond and will maximize the window. 两个图标都会响应并最大化窗口。 附上 However other applications (like TextEdit, and also the one I programmed in XCode): only the minimized icon maximizes them. 然而,其他应用程序(如TextEdit,以及我在XCode中编程的应用程序):只有最小化的图标才能最大化它们。 The "main" icon does nothing.] “主要”图标什么都不做。]

How can I make both icons maximize my application programmatically? 如何使两个图标以编程方式最大化我的应用程序?

Thanks a million! 太感谢了!

Nili 尼莉

Need to implement applicationShouldHandleReopen in order to open minimized windows from the "main" icon 需要实现applicationShouldHandleReopen才能从“main”图标打开最小化的窗口

- (BOOL)applicationShouldHandleReopen:(NSApplication *) __unused theApplication hasVisibleWindows:(BOOL)flag
{
    if (!flag){
        [[self window] makeKeyAndOrderFront:self];
    }
    return YES;
}

Clicking on the Dock icon calls: 单击Dock图标调用:

- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag

Reopen your windows in this message handler. 在此消息处理程序中重新打开您的窗口。

It is send to the Application Delegate and is part of the NSApplicationDelegate protocol. 它被发送到Application Delegate并且是NSApplicationDelegate协议的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM