为什么我的 iPhone 设备和模拟器的屏幕分辨率不同?
我使用 itouch 4G 有我的设备,我使用模拟器-4.2
我将仅画一个矩形作为示例。我使用Quartz-2d来绘制
- (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);
}
我在模拟器中运行它,整个屏幕变成绿色,然后我在我的设备上运行它,只有四分之一的屏幕变成绿色,为了使我的设备上的整个屏幕变成绿色,我必须绘制一个更大的矩形,
CGContextAddRect(context, CGRectMake(0,0,640,960));
看起来我的设备的分辨率是模拟器的两倍,
我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iPhone 上的 Retina 显示屏的分辨率是上一代手机的两倍。您的模拟器可能正在使用“iPhone”设备而不是“iPhone4”设备运行。您可以在
Hardware | 中切换。设备菜单。
您可以获得当前渲染的视图比例,
然后相应地缩放尺寸。
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
then scale your dimensions accordingly.