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

查看:105
本文介绍了Xcode中的度量单位是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

解决方案

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

查看有关在ios上进行绘图和打印的Apple文档.

修改 回答您的iPhone 4S vs 5和下一代问题.这些是实际的屏幕尺寸.分辨率是不同的. iPhone 4S和4屏幕为320x480点或640x960像素. iPhone 5、5C和5S屏幕为320x568点或640x1136像素.如果您使用的是xib,则可能会看到以前的尺寸之一,因为xib的尺寸已定义.这就是自动布局约束的出现.您在xib或情节提要中告诉您如何在屏幕上调整元素的大小/位置.您可能正在使用支柱和弹簧来决定如何在视图中重新放置项目,而不是自动布局.没关系. 即使您的xib/情节提要是iphone5大小,如果在iPhone4/4S模拟器或设备上运行应用程序时,如果在viewDidAppear方法中检查屏幕的大小,您也会看到视图边界具有相应设备的大小. 最好使用点而不是像素,因为它可以帮助开发人员从分辨率中抽象出来.您不必担心一个点有多少像素,只需要在屏幕上的点上找到项目,然后让系统为您解决分辨率问题即可.

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中的度量单位是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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