I'm trying to write a Universal Application. The display should be slightly different for different screen resolutions. But when I code like this:
- (void)viewDidLoad {
SCREEN_WIDTH=[[UIScreen mainScreen] applicationFrame].size.width;
SCREEN_HEIGHT=[[UIScreen mainScreen] applicationFrame].size.height;
NSLog(@"w:%f h:%f",SCREEN_WIDTH,SCREEN_HEIGHT);
...
}
I get output: w:320.000000 h:480.000000
even when the simulator is set to
Hardware->Device->iPhone (Retina)
Furthermore, images with this resolution display as full-screen images in the simulator.
I understand I should be getting w:640.000000 h:960.000000
.
Is it like this for anyone else? And any ideas why/how to fix?
See the related thread: here
Best Answer
UIScreen
will always report the resolution of a Retina Display device as that of a non-Retina Display device. This allows old code to run transparently on such screens. However,UIScreen
exposes ascale
property which, when combined with the bounds of the screen, can be used to determine the physical pixel resolution of a device:The resulting value on an iPhone 4 would be
{ 640.0, 960.0 }
.