在iPhone中获取屏幕分辨率 [英] Getting the screen resolution in iphone

查看:94
本文介绍了在iPhone中获取屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取屏幕的宽度和高度.我用这种方式

Hi I need to get the screen width and height. I have used this way

UIWindow* window = [UIApplication sharedApplication].keyWindow;
NSLog(@"%f",window.frame.size.width);
NSLog(@"%f",window.frame.size.height);

问题是我有iPhone 4,但分辨率显示为480x320,这是不正确的...

The problem is I have an iPhone 4 but the resolution is shown as 480x320 which is incorrect...

推荐答案

float scaleFactor = [[UIScreen mainScreen] scale];
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat widthInPixel = screen.size.width * scaleFactor;
CGFloat heightInPixel = screen.size.height * scaleFactor;

关于480x320的屏幕分辨率,这是绝对正确的,因为这给了您逻辑上的尺寸,或者您可以说尺寸为480点x 320点.

About the screen resolution of 480x320, it is absolutely right as this gives you the logical size or you can say size in points as 480 points x 320 points.

点和像素之间存在差异. Pixel 是最小的显示单位.

There is difference between a point and pixel. Pixel is the smallest unit of display.

其中 Point 是像素的集合.

对于iPhone 4,1点= 2像素
如果是iPhone 3GS,1点= 1像素

In case of iPhone 4 1 point = 2 pixel
In case of iPhone 3GS 1 point = 1 pixel

请参考文档以获取缩放界限 .

bounds :包含屏幕的边界矩形,以点为单位.
scale :此值反映了从默认逻辑坐标空间转换为该屏幕的设备坐标空间所需的比例因子.默认逻辑坐标空间是使用点测量的,其中一个点大约等于1/160英寸.如果设备的屏幕具有合理相似的像素密度,则通常将比例因子设置为1.0,以使一个点映射到一个像素.但是,像素密度明显不同的屏幕可以将此属性设置为更高的值.

这篇关于在iPhone中获取屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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