tags:

views:

233

answers:

2

I am debugging an application using iPhone 4 Simulator. I have selected it from the simulator menu (device = iPhone 4). When I run the app, the screen size is reported as 480x320 !!??

Is there something I have to modify on this app of mine (originally built for 3G/3gs) in order to make it run on iPhone 4 (yes, I have recreated all artwork as 960x640 and the artwork is on the bundle, but it is scaling it down to half the size... because it is running on 3G/3GS mode, instead of hi res).

running

CGRect cgRect =[[UIScreen mainScreen] bounds];

will result in (0,0,480,320).

Any clues?

thanks for any help.

+3  A: 

Recommended read: http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/SupportingResolutionIndependence/SupportingResolutionIndependence.html

One point does not necessarily correspond to one pixel on the screen.

A sample project, download here.

ohho
lets make it simple: CGRect cgRect =[[UIScreen mainScreen] bounds]; ......... result = (0,0,480,320).. another example: I have both images and images@2x, but hires images are not loading on iPhone 4 simulator. Just the low res ones.
Digital Robot
@Mike just to be sure, iPhone 4 simulator comes with a 960x640 pixel mode. are you running it?
ohho
if by "960x480 pixel mode" do you mean "iphone 4" selected on Hardware > Device, then, Yes.
Digital Robot
@Mike, that's weird. I did come across another bug that iOS4 code does not load a `@"image"` (no file extension) on a 3.1.x device but `@"image.png"` is OK. Just one more checking, both `image.png` and `[email protected]` should be dragged inside the Xcode project.
ohho
I am using it like.... UIImage* anImage = [UIImage imageNamed:@"Button.png"]; ... and I am expecting it to load the regular or @2x. Apple is clear when they say that you MAY not use the extension if you are creating for 4.x, but as I see, the extension must be there for the 3.x devices. right?
Digital Robot
@Mike, yes. I found `@"Button"` (without `.png`) was not loaded on a 3.x device.
ohho
A project for your reference, download: http://ho.race.hk/blog/wp-content/uploads/2010/07/Twox.zip
ohho
Thanks, great! The strangest part is that your project loads both image resolutions according to the device. Mine, don't! :-(
Digital Robot
+2  A: 

The iPhone is making the move into resolution independence. This means that things aren't measured in pixels, but in points. Points don't always correspond to pixels.

The screen size of the iPhone 3GS (and previous) is 480x320, in both points an pixels. They correspond on these devices, but in newer devices (like iPhone 4) they do not.

The iPhone 4's screen size is 960x640 in pixels, but its logical screensize is still 480x320 in points.

This allows you to keep your frame, point and size values in their original values and still support larger resolution devices.

On iPhone 4 you need to have @2x somewhere in the name of the image file and it will be used automatically on the higher resolution devices.

When @2x images are loaded, they are loaded as their original resolution, but their size property is halved to be able to work with the logical point measurments.

For instance, an image with an original size of 960x640 will report its size as 480x320 when it's asked for.

Jasarien
ok, but the hires images are still not loading. The simulator is loading the lowres images instead.
Digital Robot
Except nothing's *really* resolution-indepedendent — pixel boundaries are important for things like aligning images and stuff. They've picked an integer multiple of the original screen size so they can just use the double-pixel hack; but it's still just a hack. Finally, they are *not* points! Historic "points" have all been between 0.18 and 0.4 mm; iPhone's 0.156 mm is smaller than any of those.
tc.