macos OS X 设计决策。在最后一个窗口关闭时终止应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5480114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:52:55  来源:igfitidea点击:

OS X design decisions. Terminate the app on last window close?

cocoamacosuser-interface

提问by dawg

Unlike Windows, GNOME and most other GUI's, OS X application programs do not all terminate if the main window (or all the windows) of that application are closed.

与 Windows、GNOME 和大多数其他 GUI 不同,如果该应用程序的主窗口(或所有窗口)关闭,OS X 应用程序不会全部终止。

For example, fire up Firefox, Safari, Word, or most document based apps. Either click the red dot in the corner or type cmdWto close the window. You can see that the menu of that program is still active, and the program is still running. With OS X newbies, sometimes you will see dozens of these windowless zombies running and they wonder why their computer is getting slower.

例如,启动 Firefox、Safari、Word 或大多数基于文档的应用程序。单击角落中的红点或键入cmdW以关闭窗口。您可以看到该程序的菜单仍然处于活动状态,并且该程序仍在运行。对于 OS X 新手,有时您会看到数十个这些无窗口僵尸在运行,他们想知道为什么他们的计算机变得越来越慢。

With some document based programs, there is some sense to not terminating the application if it has no windows. For example, with Safari or Word, you can still type CmdNand get a new document window for whatever that application was designed to do: browse the web (Safari) or type a new document (Word).

对于某些基于文档的程序,如果应用程序没有窗口,则不终止应用程序是有意义的。例如,使用 Safari 或 Word,您仍然可以CmdN为该应用程序设计的任何功能键入并获取新文档窗口:浏览网页 (Safari) 或键入新文档 (Word)。

Apple is mixed with their design philosophy on this. Some close on the last window closed and some do not. Third party apps are even more mixed.

苹果公司在这方面与他们的设计理念混杂在一起。有些在最后一个窗口关闭时关闭,有些则没有。第三方应用程序更加复杂。

There are other apps that do close when their red close button is clicked. System Preferences, Dictionary, the Mac App Store, iPhoto and Calculator do terminate when the sole or last window is closed. iCal, Address Book, iTunes, DVD Player do not terminate.

单击红色关闭按钮时,还有其他应用程序会关闭。系统偏好设置、词典、Mac App Store、iPhoto 和计算器会在唯一或最后一个窗口关闭时终止。iCal、地址簿、iTunes、DVD 播放器不会终止。

What I find particularly annoying is the applications that do not have a logical "New Document" or "Open" function yet they do not terminate when the document window is closed. Example: fire up iTunes or Address Book and terminate the main window. There sits a zombie with no window and no function other than manually selecting "Quit".

我觉得特别烦人的是那些没有逻辑“新建文档”或“打开”功能但在文档窗口关闭时它们不会终止的应用程序。示例:启动 iTunes 或地址簿并终止主窗口。有一个没有窗口的僵尸,除了手动选择“退出”之外没有其他功能。

It is easy to close the application after the last window closes. Cocoa even gives you notification of that event. Just add this to your application delegate:

在最后一个窗口关闭后很容易关闭应用程序。Cocoa 甚至会通知您该事件。只需将此添加到您的应用程序委托中:

  - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
    return YES;
}

My question is this: Is there any reason I should NOT terminate my application after the last window closes? Why is this so variable on OS X software? Unless the app has a "new" or "open" or some other clearly understood reason to not terminate with no window open, the failure to terminate seems like a bug to me.

我的问题是:有什么理由不应该在最后一个窗口关闭后终止我的应用程序?为什么这在 OS X 软件上如此多变?除非应用程序有一个“新的”或“打开的”或其他一些明确理解的理由在没有窗口打开的情况下不终止,否则终止失败对我来说似乎是一个错误。

采纳答案by Dave Gallagher

Per Apple's Human Interface Guidelines(a guide for Mac developers):

根据 Apple 的人机界面指南(Mac 开发人员指南):

In most cases, applications that are not document-based should quit when the main window is closed. For Example, System Preferences quits if the user closes the window. If an application continues to perform some function when the main window is closed, however, it may be appropriate to leave it running when the main window is closed. For example, iTunes continues to play when the user closes the main window.

在大多数情况下,不是基于文档的应用程序应该在主窗口关闭时退出。例如,如果用户关闭窗口,系统偏好设置就会退出。但是,如果应用程序在主窗口关闭时继续执行某些功能,则在主窗口关闭时让它继续运行可能是合适的。例如,当用户关闭主窗口时,iTunes 会继续播放。

回答by ughoavgfhw

In general, never close a document based application when the last window closes. The user will expect to be able to open a new document without relaunching the application, and it will confuse them if they can't.

通常,不要在最后一个窗口关闭时关闭基于文档的应用程序。用户希望能够在不重新启动应用程序的情况下打开新文档,如果不能,他们会感到困惑。

For non-document based applications, you need to consider a few things:

对于非基于文档的应用程序,您需要考虑以下几点:

  1. How long does it take for my application to open? If it takes more than a second, you should probably not quit.
  2. Does my application need a window to be useful? If your application can do work without windows, you should not quit.
  1. 我的申请需要多长时间才能打开?如果花费的时间超过一秒钟,您可能不应该退出。
  2. 我的应用程序需要一个有用的窗口吗?如果您的应用程序可以在没有窗口的情况下工作,您不应该退出。


iTunes doesn't quit because, as Anne mentioned, you don't need a window to play music (question 2). It is also not based on Cocoa, so it is much more difficult to close after the last window, especially since it allows you to open windows for specific playlists so there are an indefinite number of possible windows to be open.

iTunes 不会退出,因为正如安妮所说,您不需要窗口来播放音乐(问题 2)。它也不是基于 Cocoa,因此在最后一个窗口之后关闭要困难得多,特别是因为它允许您打开特定播放列表的窗口,因此可以打开无限数量的可能窗口。

In my opinion, Address Book does not need to stay open. This could be a left-over design decision from older versions of OS X, or it could be that someone at Apple just thought it was better to leave it open (maybe so you can add a contact?). Both iTunes and Address Book provide access to their main interfaces through the Window menu, as well as a keyboard shortcut (Option+Command+1for iTunes, Command+0for Address Book).

在我看来,地址簿不需要保持打开状态。这可能是旧版 OS X 遗留下来的设计决定,也可能是 Apple 的某个人认为最好让它保持打开状态(也许这样你就可以添加联系人?)。iTunes 和地址簿都通过“窗口”菜单以及键盘快捷键(Option+ Command+1表示 iTunes,Command+0表示地址簿)提供对其主界面的访问。

回答by mcrider

The main iTunes window can be reopened from the 'Window' menu. Mail.app has similar behavior. I can't think of any applications that close when the last window is closed, and as such I don't think there's a good reason that your app should behave that way (in fact, i'm surprised its not in Apple's user experience guidelines, it would really bother me!).

可以从“窗口”菜单重新打开 iTunes 主窗口。Mail.app 有类似的行为。我想不出任何在最后一个窗口关闭时关闭的应用程序,因此我不认为您的应用程序应该以这种方式运行(事实上,我很惊讶它不在 Apple 的用户体验中)指导方针,这真的会困扰我!)。

One reason why you'd want to close e.g. the iTunes main window but keep the app open is to be able to use the app as sort of a server for third party scripts/applications. I rarely use the main iTunes interface, but instead control my music with a third party app. I also write AppleScripts for other apps that I launch instead of interacting with that app's interface.

您想要关闭例如 iTunes 主窗口但保持应用程序打开的一个原因是能够将该应用程序用作第三方脚本/应用程序的服务器。我很少使用 iTunes 主界面,而是使用第三方应用程序控制我的音乐。我还为我启动的其他应用程序编写 AppleScript,而不是与该应用程序的界面交互。