How to accommodate for the iPhone 4 screen resolution? - iphone

According to Apple, the iPhone 4 has a new and better screen resolution:
3.5-inch (diagonal) widescreen Multi-Touch display
960-by-640-pixel resolution at 326 ppi
This little detail affects our apps in a heavy way. Most of the demo apps on the net have one thing in common: They position views in the believe that the screen has a fixed size of 320 x 480 pixels. So what most (if not all) developers do is: they designed everything in such a way, that a touchable area is (for example) 50 x 50 pixels big. Just enough to tap it. Things have been positioned relative to the upper left, to reach a specific position on screen - let's say the center, or somewhere at the bottom.
When we develop high-resolution apps, they probably won't work on older devices. And if they do, they would suffer a lot from 4-times the size of any image, having to scale them down in memory.

According to Supporting High-Resolution Screens In Views, from the Apple docs:
On devices with high-resolution screens, the imageNamed:,
imageWithContentsOfFile:, and
initWithContentsOfFile: methods
automatically looks for a version of
the requested image with the #2x
modifier in its name. It if finds one,
it loads that image instead. If you do
not provide a high-resolution version
of a given image, the image object
still loads a standard-resolution
image (if one exists) and scales it
during drawing.
When it loads an image, a UIImage object automatically sets the size and
scale properties to appropriate values
based on the suffix of the image file.
For standard resolution images, it
sets the scale property to 1.0 and
sets the size of the image to the
image’s pixel dimensions. For images
with the #2x suffix in the filename,
it sets the scale property to 2.0 and
halves the width and height values to
compensate for the scale factor. These
halved values correlate correctly to
the point-based dimensions you need to
use in the logical coordinate space to
render the image.

This is purely speculation, but if the resolution really is 960 x 640 - that's exactly twice as high a resolution as the current version. It would be trivially simple for the iPhone to check the apps build target and detect a legacy version of the app and simply scale it by 2. You'd never notice the difference.

Engadget's reporting of the keynote included the following transcript from Steve Jobs
...It makes it so your apps run
automatically on this, but it renders
your text and controls in the higher
resolution. Your apps look even
better, but if you do a little bit of
work, then they will look stunning. So
we suggest that you do that
So I infer from that, if you use existing APIs your app will get scaled up. If you take advantage of new iOS4 APIs, you can get all groovy with the new pixels.

It sounds like the display will be ok but I'm concerned about the logic in my game. Will touchesBegan positions return points in the new resolution? The screen bounds will be different, these types of things could potentially be problems for me.

Scaling to a double resolution for display purpose is straight forward, but will this scalling apply to all api's that input/output a screen coordinate? If not things are going to break aren't they?
Fair enough if it's been handled extensively throughout the framework.. I would imagine there are a lot of potential api's this effects.

For people who are coming to this thread looking for a solution to a mobile web interface, check out this post on the Webkit blog: http://webkit.org/blog/55/high-dpi-web-sites/
It seems that Webkit has solved this problem four years ago.

Yes it is true.
According to WWDC it appears that apple has build it some form of automatic conversion so that the resolution for applications will not be completely off. Think up-convert for dvd to HDTV's.
My guess would be that apple knows what most of the standards developers have been using and will already be using these for an immediate conversion. Of course if you are programming an application to take advantage of the new resolution it will look much nicer than whatever the result of apples auto-conversion is.

All of your labels and system buttons will be at 326dpi but your images will still be pixel doubled until you add the hi-res resources. I am currently updating my apps. If you build and run on the iPhone 4 sim then it is presented at 50%, go to Window > Scale > 100% to see the real difference! Labels are smooth, my images look shocking!

Related

Iphone how to build UI for both resolutions 640X960 and 320X480?

since iPhone 4 now has 640X960 resolution i am confused how to build a proper UI for both 320 X 480 and 640 X 960 resolutions.. if i only use images and stuff of 640X960 resolution will it automatically adjust itself for smaller resolution iPhones.. if not what is the best way to differentiate on basis of device resolution??
You make 2 of each image - the first one at normal scale and named the usual "whatever.png". Then you make a second hi-res version of that image at double the scale and name it "whatever#2x.png". Then, iOS will handle the rest. You'll add both of those images to the project, and anywhere in the code that you reference "whatever.png", the system will take care of grabbing and using "whatever#2x.png" when and if appropriate, so you don't have to fuss with much. That's it. Simple.
In Interface Builder, just lay things out like normal using the standard sized graphics. In code as well, just reference images as usual, referring to the standard-sized images. So long as the higher-res counterpart is named with the "#2x.png" appended, everything will just work.
So, just as an example, say you currently have a project with a button image sized 40x100 named "awesomeButton.png". To support the retina resolution, create a new button image sized at 80x200, and name it awesomeButton#2x.png. Import it into your project and iOS takes care of the rest.

iPhone 4 - high resolution images are blurry

I am updating an app to have high-res images to be displayed on the new iPhone 4. My original images (in a UIImageView) were 100 by 100 pixels, so I updated my new images to be 200 by 200 pixels.
I know about the #2x convention, but my images are not stored locally in my project - they are retrieved from the web and being used for both iPhone 4 and other iPhones/iPod touches so they do not include #2x in their name.
Is there anything special I need to display these images properly? Do I need to send down separate versions depending on the device? Or can I send down a high-res version and set some sort of scale?
One issue I think may be causing this is I am building using Base SDK 3.2, which probably has no idea how to handle displays that are higher density than those pre-dating the iPhone 4. I think this may be an issue, because my problem seems rooted in the "point vs pixel" discussion in Apple's docs and the scale factor of an image:
http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/SupportingResolutionIndependence/SupportingResolutionIndependence.html
Thoughts?
Many thanks!
I've had this problem too, the problem related to a clipping mask I was applying to the image. However, I was using 4.0 base SDK, 3.0 deployment target. What I did was check for the -[UIScreen scale] method I'd pass to the mainScreen and see if it was 2.0 (if it infact responded to it). If it was, I knew the scale was 2.0, I'd then call the method that applied the clipping mask with the proper scale. The problem wasn't passing in the data with the right scale, the problem was adjusting the core graphics code to account for the scale; it was applying the clipping mask in one scale, when the image itself was in another scale. If you show us code of what you're doing, I can revise my answer to show you code that will likely help you.

What's the Best Way to Support the Multiple Art Sizes Currently Used by iOS?

Currently iOS supports three different art sizes: art for the 480x320 original iPhone screen, art for the hi-res 960x640 iPhone 4 screen, and art for the 1024x768 iPad screen, which in my experience is usually not the same as for the hi-res screen because of the different demands placed upon the different aspect ratio of the screen.
In a worst case, you could include three sizes for all of your artwork, and that's exactly what I did for the main element (cards) of my last game. However, it's ultimately wasteful in both download time and my time in creating them all.
What would y'all suggest as the best way to deal with the different requirements of the different iDevices? Here's a few general possibilities that I'm considering:
Include artwork in all 3 sizes.
Include artwork in just 1 size (the big one), but resize it on the fly as UIImages are created.
Include artwork in just 1 size (the big one), but make resized copies of it the first time a user starts up your app.
There are of course variants involving using some techniques for just some sizes (e.g., share artwork between the two big sizes, slightly resizing as needed). I'm interested in which method you'd use, with notes on the pros and cons of doing so. I expect the biggest cons are going to be: file size and any lag that might be caused in display or resizing of the objects. One of my biggest unknowns is how good of a job iOS does if you let it do the resizing, both in output quality and in timing.
I'm currently using artwork in all 3 sizes. If your artwork is in vector format and designed for both the iPhone and iPad aspect ratios, it's a simple batch action to create all 3 at the same time.
If you just include the highest resolution, the memory usage might be a problem with older iOS devices which have less memory to work with. The image quality and speed of resizing is not an issue, since both are excellent, if you let the OS resize the images. For me, I don't want to have additional code to handle resizing the same image for different devices. Otherwise it sounds like having just the large artwork and making sure it's resized correctly will be fine.

iPhone 4.0 Screen Resolution and writing robust code

Does anyone know what will happen with existing apps when they run on the iPhone 4.0 in terms of the new screen resolution? I am assuming, just like developing for the iPad that there should be no hard coded screen resolutions in your code.
I'd also like advice on the best way of writing robust code to work well on any device. For instance, detecting the screen resolution is not enough - on the iPad the screen is physically bigger so you can display more items on it. On the new iPhone the screen is the same physical size but higher resolution, so the likely thing is that you wont want to display more items, just higher resolution versions of them.
Any help would be useful,
Regards
Dave
EDIT: I have read the other similar posts, I guess what I really would like to know is what is the recommended way to write code for all App Store devices in a robust way so they a) all work b) make best use of the device.
UIKit has be redesigned so that old apps just work unmodified in the iPhone 4. There are then several things you can do, some programmatic and some by just adding higher resolution images to you app bundle.
Firstly, and most simply you can include new double res images that are used by your app with a suffix of #2x in the name. i.e., Event.png as well as Event#2x.png. [UIImage ImageNamed:] will automatically look for the a file with this suffix if it is running at the higher res.
All the other UIKit stuff now uses points instead of pixels. So for both old and new apps full screen is still 320 x 480 points. This pretty much means everything will work including touches, etc. Although they may now return fractions of a point.
The only real gotcha so far seems to be if you use CGBitmapContextCreate as this uses pixels and requires some jiggery - pokery.

Should all .png files be in power of two on the Iphone?

When creating an UIImage file from a .png to be displayed on a button, view/cell background, etc. for a standard Iphone application, should all of them be in powers of 2 for optimization reasons?
As others have said, no - but you should generally use images with even dimensions. This is because when views are positioned with the center property, it'll position an odd-dimensioned image at some half-pixel position. This will cause the image to appear blurry.
As long as you're aware of this it shouldn't really cause you any problems, but it's still a good idea to use even sizes just to be on the safe side.
(This applies for UIKit, not necessarily OpenGL)
Apple uses odd and arbitrary dimensions for all the images it adds to the interface on your behalf, such as system toolbar items. The best optimization you can do is anything that reduces compositing, which basically means setting the opaque property of views and layers whenever possible.
If you have the choice between a transparent png that will be composited over a static background and an opaque png with the background already included, you have a chance to optimize. When the images will be sliding around or the background will change, you have to composite, otherwise choose opaque.
Here is an article on optimization of iPhone images -- basically tells you why to use PNG files. The size shouldn't matter unless you are using OpenGLES.
No, this will have little or no benefit, I usually suffice at doing my own optimization using photoshop "Save for web or devices" option.
Please see http://iphonedevelopment.blogspot.com/2008/10/iphone-optimized-pngs.html for a detailed explanation about the iPhones pre-optimization of pngs.