Xcode中的计量单位是什么[英] What is the unit of measurement in Xcode

本文是小编为大家收集整理的关于Xcode中的计量单位是什么的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

这听起来可能很愚蠢,但是当我在Xcode中使用尺寸时,总帧大小等于320 * 568(宽度 *高).我很好.但是手机的分辨率实际上是不同的. iPhone 4S为640*960,5和下一代为640*1136.

我知道最后一个完全是Xcode用作单元的两倍,所以我的问题是:

Xcode使用什么单位测量?如果像素,为什么不使用 电话尺寸/分辨率作为参考?

推荐答案

它使用点. 在视网膜设备中,1分等于四个像素.在非雷纳设备中,1分等于1像素.

查看苹果在iOS上绘画和打印的文档. https://developer.apple.com/library/ios/documentation/2ddrawing/conpectual/drawingprintingios/graphicsdraphicsdrawingingovervievevievevievevievevievevievevievevievicsdrawingoverview.htmlll#/p>

特别是"点与像素"部分

编辑 回答您的iPhone 4s vs 5和下一代问题.这些是实际的屏幕尺寸.决议不同. iPhone 4S和4个屏幕是320x480点,或640x960像素. iPhone 5、5C和5S屏幕是320x568点,或640x1136像素.如果您正在使用XIB,则可能会看到以前的尺寸之一,因为XIB的尺寸定义了.这就是自动布局约束所在的地方.您在XIB或情节提要中告诉您如何在屏幕上调整/重新定位元素.您可能正在使用Strut和Springs来决定如何在视图中重新安置项目,而不是自动布局.没关系. 即使您的XIB/故事板是iPhone5的大小,在在iPhone4/4S模拟器或设备上运行应用程序时,请检查ViewDidappear方法中的屏幕大小,您会看到视图界限具有相应设备的大小. 最好使用点代替像素,因为它可以帮助开发人员从分辨率中摘要.您不必费心考虑多少像素,您只需在屏幕上的点找到项目,然后让系统照顾您的分辨率.

其他推荐答案

Xcode 10.1,Swift 4.2答案

Xcode使用点.但是,如果下一个解释,什么是要点和点数 - >>取决于您正在使用的视网膜设备.非逆转设备1点= 1像素上的基本元.在iPhone 6plus和更新的" Plus"型号上,Apple增加了3倍分辨率.

在普通视网膜设备上1点= 4像素,而不是2个! 然后苹果将像素包装到点. 在iPhone Plus型号上,Apple还使用因子1.15的缩写采样,这意味着,如果您有1242*2208,则应以1.15的速度分开,并且在设备上获得1080*1920 FullHD. https://www.paintcodeapp.com/news/ultimate-guide-to -iphone-resolutions

在此处输入图像说明

我相信最高答案,那是:

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

由于过时是错误的. 我提供了developer.apple.com的链接.

1617836级

在此处输入图像说明

其他推荐答案

另请参见UIKit Size (Points)和UIKit Scale factor: https://developer.apple.com/library/archive/documentation/deviceinformation/reference/reference/iosdevicecompatibility/displays/displays.html 在此处输入图像描述

本文地址:https://www.itbaoku.cn/post/2091140.html

问题描述

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.

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

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

推荐答案

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

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

Specially the section "Points Versus Pixels"

Edit To 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.

其他推荐答案

Xcode 10.1, Swift 4.2 answer

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

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

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.

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

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

enter image description here

其他推荐答案

See also UIKit Size (Points) and UIKit Scale factor: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html enter image description here