iPad Retina 显示器的 XCode 坐标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10078444/
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
XCode Coordinates for iPad Retina Displays
提问by xvpower
I just noticed an interesting thing while attempting to update my app for the new iPad Retina display, every coordinate in Interface Builder is still based on the original 1024x768 resolution.
我刚刚在尝试为新 iPad Retina 显示器更新我的应用程序时注意到一件有趣的事情,Interface Builder 中的每个坐标仍然基于原始的 1024x768 分辨率。
What I mean by this is that if I have a 2048x1536 image to have it fit the entire screen on the display I need to set it's size to 1024x768 and not 2048x1536.
我的意思是,如果我有一个 2048x1536 的图像让它适合显示器上的整个屏幕,我需要将它的大小设置为 1024x768 而不是 2048x1536。
I am just curious is this intentional? Can I switch the coordinate system in Interface Builder to be specific for Retina? It is a little annoying since some of my graphics are not exactly 2x in either width or height from their originals. I can't seem to set 1/2 coordinate numbers such as 1.5 it can either be 1 or 2 inside of Interface Builder.
我只是好奇这是故意的吗?我可以将 Interface Builder 中的坐标系切换为特定于 Retina 吗?这有点烦人,因为我的一些图形在宽度或高度上都不是原始图形的 2 倍。我似乎无法设置 1/2 坐标数,例如 1.5,它可以是 Interface Builder 中的 1 或 2。
Should I just do my interface design in code at this point and forget interface builder? Keep my graphics exactly 2x in both directions? Or just live with it?
我现在应该只用代码进行界面设计而忘记界面构建器吗?保持我的图形在两个方向上都精确 2 倍?或者只是忍受它?
采纳答案by PRNDL Development Studios
The interface on iOS is based on points, not pixels. The images HAVE to be 2x the size of the originals.
iOS 上的界面基于点,而不是像素。图像必须是原件尺寸的 2 倍。
Points Versus Pixels In iOS there is a distinction between the coordinates you specify in your drawing code and the pixels of the underlying device. When using native drawing technologies such as Quartz, UIKit, and Core Animation, you specify coordinate values using a logical coordinate space, which measures distances in points. This logical coordinate system is decoupled from the device coordinate space used by the system frameworks to manage the pixels on the screen. The system automatically maps points in the logical coordinate space to pixels in the device coordinate space, but this mapping is not always one-to-one. This behavior leads to an important fact that you should always remember:
One point does not necessarily correspond to one pixel on the screen. The purpose of using points (and the logical coordinate system) is to provide a consistent size of output that is device independent. The actual size of a point is irrelevant. The goal of points is to provide a relatively consistent scale that you can use in your code to specify the size and position of views and rendered content. How points are actually mapped to pixels is a detail that is handled by the system frameworks. For example, on a device with a high-resolution screen, a line that is one point wide may actually result in a line that is two pixels wide on the screen. The result is that if you draw the same content on two similar devices, with only one of them having a high-resolution screen, the content appears to be about the same size on both devices.
In your own drawing code, you use points most of the time, but there are times when you might need to know how points are mapped to pixels. For example, on a high-resolution screen, you might want to use the extra pixels to provide extra detail in your content, or you might simply want to adjust the position or size of content in subtle ways. In iOS 4 and later, the UIScreen, UIView, UIImage, and CALayer classes expose a scale factor that tells you the relationship between points and pixels for that particular object. Before iOS 4, this scale factor was assumed to be 1.0, but in iOS 4 and later it may be either 1.0 or 2.0, depending on the resolution of the underlying device. In the future, other scale factors may also be possible.
点与像素 在 iOS 中,您在绘图代码中指定的坐标与底层设备的像素之间存在区别。使用 Quartz、UIKit 和 Core Animation 等原生绘图技术时,您可以使用逻辑坐标空间指定坐标值,该空间以点为单位测量距离。该逻辑坐标系与系统框架用于管理屏幕像素的设备坐标空间分离。系统自动将逻辑坐标空间中的点映射到设备坐标空间中的像素,但这种映射并不总是一对一的。这种行为导致了一个重要的事实,你应该永远记住:
一个点不一定对应屏幕上的一个像素。使用点(和逻辑坐标系)的目的是提供与设备无关的一致大小的输出。点的实际大小无关紧要。点的目标是提供一个相对一致的比例,您可以在代码中使用它来指定视图和渲染内容的大小和位置。点如何实际映射到像素是由系统框架处理的细节。例如,在具有高分辨率屏幕的设备上,一个点宽的线实际上可能会在屏幕上产生一个两个像素宽的线。结果是,如果您在两个相似的设备上绘制相同的内容,其中只有一个具有高分辨率屏幕,
在您自己的绘图代码中,您大部分时间都使用点,但有时您可能需要知道点如何映射到像素。例如,在高分辨率屏幕上,您可能希望使用额外的像素为您的内容提供额外的细节,或者您可能只想以微妙的方式调整内容的位置或大小。在 iOS 4 和更高版本中,UIScreen、UIView、UIImage 和 CALayer 类公开了一个比例因子,它告诉您该特定对象的点和像素之间的关系。在 iOS 4 之前,这个比例因子被假定为 1.0,但在 iOS 4 及更高版本中,它可能是 1.0 或 2.0,具体取决于底层设备的分辨率。将来,其他比例因子也可能是可能的。
回答by strings42
This is intentional on Apple's part, to make your code relatively independent of the actual screen resolution when positioning controls and text. However, as you've noted, it can make displaying graphics at max resolution for the device a bit more complicated.
这是 Apple 有意为之,目的是使您的代码在定位控件和文本时相对独立于实际屏幕分辨率。但是,正如您所指出的,它可以使设备以最大分辨率显示图形变得更加复杂。
For iPhone, the screen is always 480 x 320 points. For iPad, it's 1024 x 768. If your graphics are properly scaled for the device, the impact is not difficult to deal with in code. I'm not a graphic designer, and it's proven a bit challenging to me to have to provide multiple sets of icons, launch images, etc. to account for hi-res.
对于 iPhone,屏幕始终为 480 x 320 点。对于 iPad,它是 1024 x 768。如果您的图形为设备正确缩放,则在代码中不难处理这种影响。我不是平面设计师,事实证明,必须提供多组图标、启动图像等来解释高分辨率对我来说有点挑战。
Apple has naming standards for some image types that minimize the impact on your code:
Apple 为某些图像类型制定了命名标准,以最大限度地减少对代码的影响:
That doesn't help you when you're dealing with custom graphics inline, however.
但是,当您处理内联自定义图形时,这对您没有帮助。