Mac应用程序的窗口大小 [英] Window Size for Mac application

查看:1935
本文介绍了Mac应用程序的窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用Cocoa的Mac应用程序开发的新手。我很困惑,应该是窗口/视图大小。像在iOS应用程序,我们有适当的尺寸为小型iPod以及最新的iPod。但如何在Cocoa应用程序中设置大小。



此外,我想将部署目标设置为不支持AutoLayout的OS X 10.6。



那么,什么是一个很好的方法来调整窗口的大小,以适应每个桌面?

解决方案

在为OS X下的显示设置窗口时需要考虑几件事。



首先,显示器的大小区。您可以使用

  NSRect frame = [[NSScreen mainScreen] frame]; 

但这有点简单,因为用户可能正在显示Dock,并且几乎总是有菜单栏显示。因此,确定桌面最大显示区域的更好方法是:

  NSRect frame = [[NSScreen mainScreen] visibleFrame] ; 





正如其他人所指出的,这个矩形很少是窗口最​​理想的尺寸。还要理解,此矩形仅仅是一个起点,因为您的用户可能有多个显示,它们有助于显示窗口的总面积。但是当显示一个新窗口时,你总是从这个矩形开始。查看 NSScreen 的文档来确定这一点;上述方法将为您提供一个跳板。



我不知道你打算如何创建和使用你的窗口,但除了最简单的应用程序,你可能会使用NSWindowController的子类。如果是这样,它将是你的窗口的委托。所以有一个重要的窗口委托方法,你需要实现它,它是这样的:

   - (NSRect) windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame 

'窗口框架的位置和大小。当窗口被放大到所谓的标准状态(相对于用户制作的大小,用户状态)时,窗口调用它。换句话说,它是最适合您窗口内容的矩形,但要记住描述安全区域的矩形,您可以在其中显示它。不幸的是,我不能告诉你如何编写代码,因为它完全取决于窗口中显示的内容。



然后, '正确'的定义是完全不同于iOS中的定义。在您的努力中向您表示最诚挚的祝福。


I am new to Mac application development using Cocoa. I am confused as to what should be the window/view size. Like in an iOS app we have proper dimensions for small iPod as well as latest iPods. But how to set the size in a Cocoa App.

Also I want to set the deployment target to OS X 10.6, which does not support AutoLayout.

So what would be a good way to resize the windows which should fit every desktop?

解决方案

There are a couple of things you need to consider when sizing windows for a display under OS X.

First, there's the size of the display area. You could use

NSRect frame = [[NSScreen mainScreen] frame];

but that's a bit simplistic because the user may be displaying the Dock, and there's almost always the menu bar displayed as well. So a better way of determining the maximum display area for the Desktop would be:

NSRect frame = [[NSScreen mainScreen] visibleFrame];

which respects the menu bar and Dock.

As others have pointed out, this rectangle is seldom the most ideal size for a window. Understand too that this rectangle is only a starting point, because your user may have multiple displays, and they contribute to the total area in which a window may be displayed. But when displaying a new window, you always start within this rectangle. Look to NSScreen's documentation to determine this; the methods above will provide a springboard to your understanding.

I don't know how you plan to create and use your window, but for all but the most simple applications, you'll probably use a subclass of NSWindowController with it. If so, it will be your window's delegate. And so there's an important window delegate method that you'll need to implement in it, and it's this:

- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame

This is where you determine the 'standard' location and size of your window's frame. It's called by the window when the window is zoomed 'out' to what is called the "standard state" (versus the size the user makes it, the "user state"). In other words, it's the rectangle that best suits the content of your window, yet keeps in mind the rectangle describing the 'safe' area in which you can display it. Unfortunately, I can't tell you exactly how to code it, because it depends entirely on what you're displaying inside your window.

You can see, then, that the definition of 'proper' is something entirely different from that in iOS. Best wishes to you in your endeavors.

这篇关于Mac应用程序的窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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