xcode Mac OS X 应用程序的最小窗口大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5496868/
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
Minimum window size of a Mac OS X application
提问by Leo
Two questions here.
这里有两个问题。
First question, In my Mac OS X application the window has resizing enabled. My window contents are on a 500x500 window size. Problem is that user can resize it so some of the contents cutts off. What I need to do so user can only resize to a minimum size (In my case 500x500)?
第一个问题,在我的 Mac OS X 应用程序中,窗口已启用调整大小。我的窗口内容是 500x500 的窗口大小。问题是用户可以调整它的大小,因此某些内容会被切断。我需要做什么以便用户只能调整到最小尺寸(在我的情况下为 500x500)?
Second question, When I close my Mac application (by clicking red cross button on window top) the app icon stays in the dock at the bottom. When user click on it again it does not fire up the application unless user quit the application all togeter and relaunches it again. What settings do I need so user can close and relaunch it by clicking dock icon?
第二个问题,当我关闭我的 Mac 应用程序(通过单击窗口顶部的红十字按钮)时,应用程序图标保留在底部的停靠栏中。当用户再次单击它时,它不会启动应用程序,除非用户一起退出应用程序并再次重新启动它。我需要什么设置才能让用户通过单击停靠栏图标关闭并重新启动它?
Thanks
谢谢
回答by DarkDust
Use -[NSWindow setMinSize:]to set the minimum size programmatically, but you can also set the minimum size inside Interface Builder (look at the tab with the sizes).
使用-[NSWindow setMinSize:]以编程方式设置最小尺寸,但您也可以在 Interface Builder 中设置最小尺寸(查看带有尺寸的选项卡)。
To make the application quit when the window is closed, you need to add this to your app delegate:
要在窗口关闭时退出应用程序,您需要将其添加到您的应用程序委托中:
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
return YES;
}