点之间的英寸 iPhone
我需要计算任何 iOS 设备上两次触摸之间的距离(以英寸为单位)。
有没有办法在 iOS sdk 中将像素转换为英寸?
如果您将其安装在任何设备上,甚至您在 iPad 上安装 iPhone 应用程序并点击 2x 按钮,这都需要起作用。
这可能吗?
I need to calculate the distance, in inches, between two touches on any iOS device.
Is there a way to get convert pixels to inches in the iOS sdk?
This needs to work if you install it on any device and even if you install an iPhone app on an iPad and hit the 2x button.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须计算出显示器的 PPI(每英寸像素数),然后才能将像素转换为英寸。但是我还没有找到任何方法以编程方式获取这些值。我认为你应该对其进行硬编码并确定在哪个设备上决定使用哪个 PPI 值。但这不是未来的保存。
要确定两次触摸之间的像素距离,请参阅 如何在 Xcode for iOS 中输出两个触摸点之间的距离?。
检测 Retina 显示屏 会告诉您是否使用的是 iPhone4。
查看 Erica Sadun 的 uidevice-extension 库。
wikipedia.org 上的按像素密度排列的显示列表。
You'll have to figure out the PPI(pixels per inch) of the display, with that you can convert pixels to inches. However I haven't found any way to get those values programmatically. I think you should hard code it and determine on which device you are to decide which PPI value to use. This is not future save however.
To determine the distance in pixels between two touches refer to How exactly do I output the distance between two touch points in Xcode for iOS?.
Detect Retina Display will tell you if you are on an iPhone4.
Have a look at Erica Sadun's uidevice-extension lib.
List of displays by pixel density at wikipedia.org.