Lingyong Wang
Lingyong Wang

Reputation: 31

why my iphone device and simulator has different screen resolution?

i use itouch 4G has my device and i use simulator-4.2
i will just draw a rectangle as an example. i use Quartz-2d to draw

- (void)drawRect:(CGRect)rect { 
// Get a graphics context, saving its state
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);

// Reset the transformation
CGAffineTransform t0 = CGContextGetCTM(context);
t0 = CGAffineTransformInvert(t0);
CGContextConcatCTM(context,t0);

// Draw a green rectangle
CGContextBeginPath(context);
CGContextSetRGBFillColor(context, 0,1,0,1);
CGContextAddRect(context, CGRectMake(0,0,320,480));
CGContextClosePath(context);
CGContextDrawPath(context,kCGPathFill);

CGContextRestoreGState(context);

}

i run it in the simulator, the whole screen becomes green, then i run this on my device, only the quarter of the screen becomes green, in order to make the whole screen green on my device, i have to draw a larger rectangle

  CGContextAddRect(context, CGRectMake(0,0,640,960));

seem like my device has twice resolution than the simulator,
how can i fix this?

Upvotes: 0

Views: 618

Answers (1)

Paul Alexander
Paul Alexander

Reputation: 32377

The Retina display on the iPhone is twice the resolution of the previous generation of phones. Your simulator is probably running using the 'iPhone' device rather than the 'iPhone4' device. You can switch in the Hardware | Device menu.

You can get the current scale of view you're rendering to with

[self.layer contentsScale]

then scale your dimensions accordingly.

Upvotes: 2

Related Questions