为什么我的 iPhone 设备和模拟器的屏幕分辨率不同?

发布于 2024-10-10 08:23:47 字数 876 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2024-10-17 08:23:47

iPhone 上的 Retina 显示屏的分辨率是上一代手机的两倍。您的模拟器可能正在使用“iPhone”设备而不是“iPhone4”设备运行。您可以在Hardware | 中切换。设备菜单。

您可以获得当前渲染的视图比例,

[self.layer contentsScale]

然后相应地缩放尺寸。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文