Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone's retina display in the simulator

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.

like image 663
Oysio Avatar asked Jul 18 '10 16:07

Oysio


People also ask

Is there an iPhone simulator?

The Apple iOS Simulator, which ships as part of Xcode, is a tool for developing and prototyping your mobile app. While the iOS Simulator can be used to test your app's basic behaviour, it is severely limited as a testing platform.

How do I connect my iPhone to simulator?

How to select your iPhone as the “Simulator” Device. Simulator is in quotes here since this will create an actual app on your phone; it's no longer a simulation. Open up a project in Xcode and click on the device near the Run ▶ button at the top left of your Xcode screen. Plug your iPhone into your computer.

What is iPhone simulator?

Simulator allows you to rapidly prototype and test builds of your app during the development process. Installed as part of the Xcode tools, Simulator runs on your Mac and behaves like a standard Mac app while simulating an iPhone, iPad, Apple Watch, or Apple TV environment.


2 Answers

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;
}
like image 51
drawnonward Avatar answered Oct 05 '22 17:10

drawnonward


Regarding your second question about resolution, maybe this will help you.
From iOS4 and later 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.

like image 21
Kb. Avatar answered Oct 05 '22 17:10

Kb.