OS X 设计决策。在最后一个窗口关闭时终止应用程序?
与 Windows、GNOME 和大多数其他 GUI 不同,如果 OS X 应用程序的主窗口(或所有窗口)关闭,则该应用程序不会全部终止。
例如,启动 Firefox、Safari、Word 或大多数基于文档的应用程序。单击角落中的红点或输入 cmdW 关闭窗口。您可以看到该程序的菜单仍然处于活动状态,并且该程序仍在运行。对于 OS X 新手来说,有时您会看到数十个无窗口僵尸正在运行,他们想知道为什么他们的计算机变得越来越慢。
对于某些基于文档的程序,如果应用程序没有窗口,则不终止该应用程序是有意义的。例如,使用 Safari 或 Word,您仍然可以键入 CmdN 并获得一个新文档窗口,以执行该应用程序设计的任何操作:浏览网页 (Safari) 或键入一个新文档(Word)。
苹果在这方面融合了他们的设计理念。有些在最后一个窗口关闭时关闭,有些则不关闭。第三方应用程序的情况更加复杂。
还有其他应用程序在单击红色关闭按钮时会关闭。当唯一或最后一个窗口关闭时,系统偏好设置、词典、Mac App Store、iPhoto 和计算器都会终止。 iCal、地址簿、iTunes、DVD 播放器不会终止。
我觉得特别烦人的是那些没有逻辑“新建文档”或“打开”功能的应用程序,但在关闭文档窗口时它们不会终止。示例:启动 iTunes 或地址簿并终止主窗口。那里坐着一个僵尸,没有窗户,除了手动选择“退出”之外没有任何功能。
最后一个窗口关闭后,很容易关闭应用程序。 Cocoa 甚至会向您发送该事件的通知。只需将其添加到您的应用程序委托中:
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
return YES;
}
我的问题是:有什么理由我不应该在最后一个窗口关闭后终止我的应用程序?为什么 OS X 软件上的变化如此之大?除非应用程序有“新”或“打开”或其他一些明确理解的原因在没有打开窗口的情况下不终止,否则终止失败对我来说似乎是一个错误。
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.
For example, fire up Firefox, Safari, Word, or most document based apps. Either click the red dot in the corner or type cmdW to 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.
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 CmdN and get a new document window for whatever that application was designed to do: browse the web (Safari) or type a new document (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.
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".
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:
- (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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Apple 的 人机界面指南(Mac 开发者指南):
Per Apple's Human Interface Guidelines (a guide for Mac developers):
一般来说,当最后一个窗口关闭时,切勿关闭基于文档的应用程序。用户希望能够在不重新启动应用程序的情况下打开新文档,如果不能,他们会感到困惑。
对于非基于文档的应用程序,您需要考虑以下事项:
iTunes 不会退出,因为正如 Anne 提到的,您不需要窗口来播放音乐(问题 2)。它也不基于 Cocoa,因此在最后一个窗口之后关闭要困难得多,特别是因为它允许您打开特定播放列表的窗口,因此可能打开的窗口数量不定。
在我看来,地址簿不需要保持打开状态。这可能是旧版本 OS X 遗留下来的设计决策,也可能是 Apple 的某个人认为最好将其保持打开状态(也许这样您就可以添加联系人?)。 iTunes 和地址簿都可以通过窗口菜单以及键盘快捷键(Option+Command+1 来访问其主界面。 iTunes,命令+0 用于地址簿)。
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:
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.
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+1 for iTunes, Command+0 for Address Book).
可以从“窗口”菜单重新打开 iTunes 主窗口。 Mail.app 也有类似的行为。我想不出有任何应用程序会在最后一个窗口关闭时关闭,因此我认为您的应用程序没有充分的理由应该这样做(事实上,我很惊讶它不在苹果的用户体验中)指导方针,这真的会让我很困扰!)。
您想要关闭 iTunes 主窗口但保持应用程序打开的原因之一是能够将该应用程序用作第三方脚本/应用程序的服务器。我很少使用 iTunes 主界面,而是使用第三方应用程序控制我的音乐。我还为我启动的其他应用程序编写 AppleScript,而不是与该应用程序的界面进行交互。
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!).
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.