views:

474

answers:

2

I'm getting a bit confused on how to use the simulator to build applications that need to support the new higher resolution of the iphone 4.

I would except when selecting the iphone4 simulator to run the app on that [[UIScreen mainScreen] bounds] would give me 960x640 back, but instead it still giving me the old resolution (480x320) ?

Although the iphone4 simulator appears as a giant phone on my screen, it appears that it still consists of only 480x320 pixels. For instance when I would want to display something on line 700, it'll just fall ofscreen ?

Thanks for any input on this.

+4  A: 

UIScreen has a new scale method. Multiply the bounds.size by the scale to get the pixels. You can think of unscaled values as being points, or virtual pixels.

Note that UIScreen has had a scale method since at least 3.2 but it has only been documented since 4.0 so respondsToSelector will trick you. I check UIImage for scale even when I want to know about UIScreen.

UIScreen *mainScreen = [UIScreen mainScreen];
CGFloat scale = [mainScreen scale];
CGRect bounds = [mainScreen bounds];
CGRect pixels = bounds;

if ( scale > 0 ) {
    pixels.origin.x *= scale;
    pixels.origin.y *= scale;
    pixels.size.width *= scale;
    pixels.size.height *= scale;
}
drawnonward
Thx for your answer. Any chance of answering my second question as well?
Oysio
+2  A: 

Regarding your second question about resolution, maybe this will help you.
From iOS4 and later the there are pixels, points and scale factors.

[[UIScreen mainScreen] bounds] 

bounds will return points (480x320) not pixels (960x640).
iOS4 Application Programming Guide (Points versus Pixels):

In iOS 4 and later, the UIScreen, UIView, UIImage, and CALayer classes expose a scale factor that tells you the relationship between points and pixels for that particular object. Before iOS 4, this scale factor was assumed to be 1.0, but in iOS 4 and later it may be either 1.0 or 2.0, depending on the resolution of the underlying device. In the future, other scale factors may also be possible.

Kb