开发者

How to Asking Device Screen Ratio (iphone or ipad)?

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开发者_StackOverflow 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?


You could simply ask for the UIApplication's window size.

[UIApplication sharedApplication].keyWindow.bounds

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜