xcode Xcode中的计量单位是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24142350/
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-09-15 05:02:54  来源:igfitidea点击:

What is the unit of measurement in Xcode

iosxcodeframeunits-of-measurement

提问by Gil Sand

This might sound silly but when i'm working with sizes in Xcode, the total frame size is equal to 320 * 568 ( width * height ). I'm fine with that. But the resolution of the phone is actually different. The iphone 4S is 640*960 & the 5 and next generations are 640*1136.

这可能听起来很傻,但是当我在 Xcode 中处理尺寸时,总框架尺寸等于 320 * 568 ( width * height )。我没问题。但是手机的分辨率其实是不一样的。iphone 4S是640*960 & 5代和下一代是640*1136。

I know the last one is exactly double of what xcode is using as units, so my question is :

我知道最后一个正好是 xcode 用作单位的两倍,所以我的问题是:

What unit of measurement does XCode use? If it pixels, why not use the phone size/resolution as reference?

XCode 使用什么度量单位?如果是像素,为什么不使用手机尺寸/分辨率作为参考?

回答by The dude

It uses points. In retina devices, 1 point equals four pixels. In non-retina devices, 1 points equals 1 pixel.

它使用积分。在视网膜设备中,1 点等于 4 个像素。在非视网膜设备中,1 个点等于 1 个像素。

Check out apple's documentation on drawing and printing on ios. https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW7

查看苹果关于在 ios 上绘图和打印的文档。 https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW7

Specially the section "Points Versus Pixels"

特别是“点与像素”部分

EditTo answer your iphone 4S vs 5 and next generation question. These are actual screen sizes. The resolutions are different. The iPhone 4S and 4 screens are 320x480 points, or 640x960 pixels. iPhone 5, 5C and 5S screens are 320x568 points, or 640x1136 pixels. If you are working with xibs, you may be seeing one of the previous sizes because xibs have a size defined. That's where auto layout constraints come in. You tell in the xib or storyboard how you want the elements to be resized/relocated in the screen. You may be using struts and springs to decide how to relocate items in your view instead of auto layout. It's ok. Even if your xib / storyboard is iphone5 size, if you check the size of the screen in your viewDidAppear methods when running the app on a iPhone4/4S simulator or device, you will see that your view bounds have the size of the corresponding device. It's better to use points instead of pixels because it helps the developer abstract from resolutions. You don't have to bother about how many pixels are a point, you just locate items at points in the screen and let the system take care of the resolution for you.

编辑回答您的 iphone 4S vs 5 和下一代问题。这些是实际的屏幕尺寸。分辨率不同。iPhone 4S 和 4 屏幕为 320x480 点,或 640x960 像素。iPhone 5、5C 和 5S 屏幕为 320x568 点,或 640x1136 像素。如果您正在使用 xibs,您可能会看到以前的尺寸之一,因为 xibs 已定义了尺寸。这就是自动布局约束的用武之地。您可以在 xib 或故事板中说明您希望元素如何在屏幕中调整大小/重新定位。您可能正在使用 struts 和 springs 来决定如何在视图中重新定位项目而不是自动布局。没关系。即使您的 xib / storyboard 是 iphone5 大小,如果您在 iPhone4/4S 模拟器或设备上运行应用程序时在 viewDidAppear 方法中检查屏幕大小,您将看到您的视图边界具有相应设备的大小。最好使用点而不是像素,因为它可以帮助开发人员从分辨率中抽象出来。您不必担心一个点有多少像素,您只需在屏幕上的点处定位项目,让系统为您处理分辨率。

回答by swift2geek

Xcode 10.1, Swift 4.2 answer

Xcode 10.1,Swift 4.2 答案

Xcode uses points. But in case of next explanation what is point and how much pixels in point -> it depends what retina device are you using. Basicaly on non-retina devices 1 point = 1pixel. On iphone 6plus and newer "plus" models, apple added 3x resolution. enter image description here

Xcode 使用积分。但是在下一个解释的情况下,点是什么以及点中有多少像素 - >这取决于您使用的是哪种视网膜设备。基本上在非视网膜设备上 1 点 = 1 像素。在 iphone 6plus 和更新的“plus”型号上,苹果增加了 3 倍分辨率。 在此处输入图片说明

On normal retina devices 1 point = 4 pixels, NOT 2!! then apple packing that pixels into point. At iPhone plus models apple also uses downsampling with factor 1.15 which means for example, if you have 1242*2208 then it should be devided on 1.15 and you get your 1080*1920 fullHD on your device. https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

在普通视网膜设备上 1 点 = 4 像素,而不是 2 !!然后苹果将这些像素打包成点。在 iPhone plus 机型上,苹果还使用因子为 1.15 的下采样,这意味着,例如,如果你有 1242*2208,那么它应该被划分为 1.15,你的设备上就会得到 1080*1920 的全高清。 https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

enter image description here

在此处输入图片说明

I believe that the top answer, which is:

我相信最重要的答案是:

It uses points. In retina devices, 1 point equals two pixels. In non-retina devices, 1 points equals 1 pixel.

它使用积分。在视网膜设备中,1 点等于两个像素。在非视网膜设备中,1 个点等于 1 个像素。

is wrong because of outdate. I provided a link to developer.apple.com.

因为过时是错误的。我提供了一个到 developer.apple.com 的链接。

https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale

https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale

enter image description here

在此处输入图片说明