如何询问设备屏幕比例(iphone或ipad)?
我想为 iphone/ipad) 游戏创建块。我想使用相同的模型,所以我需要屏幕尺寸来编码。 例如 iPhone 在 X 坐标上有 320 个像素。我们有 8 个块,因此 320/8 = 40 iphone 在 Y 坐标中有 480 个像素。我们有 12 个区块,所以 480/12 = 40 ipad 在 X 坐标上有 768 个像素。我们有 8 个区块,所以 768/8=96 ipad 的 Y 坐标有 1024 个像素。我们有 12 个块,所以 1024/12=8
但我想要求对像素进行编程。它了解哪个设备正在运行,因此可以自动定义像素。我该怎么做?
I want to create blocks for a iphone/ipad) game. I want to use same model so i need screen sizes for coding.
For example iPhone has 320 pixels in X coordinate. we have 8 blocks, so 320/8 = 40 iphone has 480 pixels in Y coordinate. we have 12 blocks, so 480/12 = 40
ipad has 768 pixels in X coordinate. we have 8 blocks, so 768/8=96
ipad has 1024 pixels in Y coordinate. we have 12 blocks, so 1024/12=8
But i want to ask to program for pixels. It understands which device is running so define pixels otomatically. How can i do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地询问 UIApplication 的窗口大小。
请记住,此处返回的值以点而不是像素为单位进行测量。这意味着无论分辨率如何,尺寸都是相同的(即 iPhone 3G 屏幕和 iPhone 4 屏幕的尺寸相同,即使 iPhone 4 的像素数量是 iPhone 4 的两倍)。
对于非视网膜屏幕,1 点 = 1 像素。在视网膜屏幕上,您需要检查屏幕的比例以确定像素的转换。
You could simply ask for the UIApplication's window size.
Keep in mind that the value returned here is measured in points not pixels. That means that the size is the same regardless of resolution (i.e. an iPhone 3G screen and an iPhone 4 screen measure the same even though the iPhone 4 has twice as many pixels)
For non-retina screens one point = one pixel. On retina screens you would need to check for the screen's scale to determine the conversion to pixels.