如何使 iphone 和 iphone4-retina 兼容的应用程序(在 cocos2d 中完成)轻松适应 ipad?
我的问题很简单: 1.我制作了一个iPhone应用程序,全部在cocos2d中完成。 2.我将其改编为iphone4-retina,所有PNG文件都有其-hd副本。
在 iPhone 中运行,应用程序正确显示 (320x480)。 在iPhone4-retina中运行,该应用程序也能正确显示(640x960)。
但在 iPad 上运行时,如果该应用程序仅设置为 iPhone,则它可以正确运行,但只能以 iPhone 分辨率 (320x480) 运行。如果应用程序设置为iPhone/iPad,当然会显示错误。
我确信应该有一个选项可以强制兼容视网膜的 iPhone 应用程序也可以在 iPad 上作为视网膜运行(苹果人不能傻到错过它),但我就是找不到它。
选项在哪里?或者,是否有其他替代方案,cocos2d 有一个同样简单的开关来完成这项工作?我不需要诸如使用相对坐标之类的建议或任何需要修改超过二十行代码的内容。
My question is simple:
1. I made an iphone app all done in cocos2d.
2. I adapted it to iphone4-retina, with all PNG files have their -hd copy.
Run in iPhone, the app displayed correctly (320x480).
Run in iPhone4-retina, the app also displayed correctly (640x960).
But run in iPad, if the app is set to iPhone only, it run correctly, but only as iPhone resolution (320x480). If the app is set to iPhone/iPad, of cause it will display wrong.
I'm sure there should be an option that force a retina-compitable iPhone app also run as retina on iPad (apple guys cannot be silly enough to miss it), but I just couldn't find it.
Where's the option? Or, is there an alternative that cocos2d has a same-easy switch to do the job? I do not need suggestions such as using relative coordinates or anything requires modifications more than twenty code-lines.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,iPhone应用程序还没有自动适应iPad的功能。您仍然应该能够为 iPhone 和 iPad 创建通用应用程序,然后根据您是在一台设备还是另一台设备上运行来重新创建 UI。
具体来说,您可以:
为通用应用程序(armv6 和 armv7,针对 iPad 和 iPhone)创建一个 XCode 项目,然后导入现有项目(源、资源、设置)。
1b。 (您可以修改现有项目,但这可能很难正确执行。)
除了 iPhone 的图标和默认图像之外,还按照 iPad 指南添加
至于其余的,您可以采用与此处突出显示的方法类似的方法对于 Xibs:
针对 iPad 进行测试:
+(Bool)isIpad{
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}
加载前翻译图像名称:
+(NSString*)properImageFileName:(NSString*)imageName {
if ([xxxx 是Ipad]) {
返回 [NSString stringWithFormat:@"ipad_%@", imageName];
} 别的 {
返回图像名称;
}
}
,如果您使用 iPhone,图像名称不会更改,并且将遵循 iPhone 视网膜显示约定;如果您使用的是 iPad,则可以即时更改名称并使用正确的图像。 (当然,您可以使用您喜欢的约定来识别 iPad 图像)。
这应该使它变得非常微不足道,但请记住,在通用应用程序中包含所有图像会产生尺寸费用。
As far as I know, there is no automatic adaptation of an iPhone app to iPad. You still should be able to create a universal app for both iPhone and iPad and then re-create your UI based on whether you are running on one device or the other.
Specifically, you could:
Create an XCode project for a universal app (armv6 and armv7, targeting iPad and iPhone) and import there your existing project (source, resources, settings).
1b. (you could modify your existing project, but this could be trickier to do correctly.)
add icons and default images as per iPad guidelines in addition to those you have for iPhone;
As to the rest, you could follow a similar approach to the one highlighted here for Xibs:
test for iPad:
+(Bool)isIpad{
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}
translate image name before loading:
+(NSString*)properImageFileName:(NSString*)imageName {
if ([xxxx isIpad]) {
return [NSString stringWithFormat:@"ipad_%@", imageName];
} else {
return imageName;
}
}
Thus, if you are on iPhone, image names are not changed and will follow the iPhone convention for retina display; if you are on iPad, you change the name on the fly and use the right image. (of course, you can use the convention you prefer to identify iPad images).
This should make it pretty trivial, but keep in mind the size toll that having all the images in your universal app tolls.