为通用应用程序准备图形资源
根据我在其他地方读到的内容,Apple 建议每种图形资源都有多个版本,因此 iPhone 4 之前的版本、iPhone 4(配备视网膜显示屏)和 iPad 之间的质量将得到保留。但我使用的技术只需要一种资产即可满足所有三种情况。
我将每个图形设置为 iPhone 4 和 iPad 所需的尺寸,例如 500x500 像素的猫。我将其命名为[电子邮件受保护]。当我在 iPhone 上读到它时:
CGRect catFrame = CGRectMake(0.0f, 0.0f, 250.0f, 250.0f);
UIImageView *theCat = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myCat"]];
theCat.frame = catFrame;
[self.view addSubview:theCat];
[theCat release];
对于 iPad,我做了完全相同的事情,除了:
CGRect catFrame = CGRectMake(0.0f, 0.0f, 500.0f, 500.0f);
这似乎在所有三种情况下都工作得很好,并且大大减少了图形文件的数量(和大小)。这个技术有什么问题吗?
From what I've read elsewhere, Apple recommends multiple versions of every graphical asset, so quality will be retained between pre-iPhone 4, iPhone 4 (with the retina display), and the iPad. But I'm using a technique that only requires one asset for all three cases.
I make each graphic the size I need for the iPhone 4 and the iPad, say a cat at 500x500 pixels. I name it [email protected]. When I read it in for the iPhone:
CGRect catFrame = CGRectMake(0.0f, 0.0f, 250.0f, 250.0f);
UIImageView *theCat = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myCat"]];
theCat.frame = catFrame;
[self.view addSubview:theCat];
[theCat release];
for the iPad, I do exactly the same thing, except for:
CGRect catFrame = CGRectMake(0.0f, 0.0f, 500.0f, 500.0f);
This seems to work fine in all three cases, and greatly reduces the number (and size) of graphic files. Is there anything wrong with this technique?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查一下:http://vimeo.com/30667638
我们很快就会发布它。如果您对 Beta 测试感兴趣,请给我留言编辑
Check this: http://vimeo.com/30667638
We are releasing it soon. If you are interested in beta testing it drop me a lineEdit
这个问题已经流传很长时间了,所以我将根据我最近开发的几个应用程序的经验来“回答”它。
我认为没有理由为视网膜显示屏和非视网膜显示屏 iPhone 提供单独的图像资源。我上面概述的技术似乎效果很好。
也许,人们会想要 iPad 的一个单独的资源(“资源文件”),主要是为了改变屏幕的宽高比。就我而言(儿童游戏的精灵),我能够在 iPad 上使用许多 iPhone 图像。 “外观”有点不同,但我节省了很多文件空间。
当然,这是否适合您将取决于您项目的独特属性。
This question has been a long time in circulation, so I will "answer" it based on my experience with the last couple of apps I've worked on.
I see no reason to have a separate image asset for retina display and non-retina display iPhones. The technique I outlined above seems to work just fine.
Probably, one will want a separate asset ("resource file") for the iPad, mostly for the change in aspect ratio of the screen. In my case (sprites for children's games) I was able to use many of the iPhone images on the iPad. The "look" was a little different, but I saved a lot of file space.
Whether this works for you will, of course, depend on the unique properties of your project.
并非所有图像都能很好地缩放,即使是 50%。抖动或图案可能会扭曲。一般来说,以 1/2、1/4 等系数(除以二)进行缩放会产生最佳结果,但使用 Photoshop 中使用的高级算法进行缩小会产生更好的结果。
因此,在大多数情况下,这可以产生可接受的结果。
Not all images scale well, even at 50%. dithering or patterns might get distorted. In general, scaling at factors of 1/2, 1/4 etc (dividing by two) will result in best results, but scaling down using an advanced algorithm like used in Photoshop will produce better results.
So, in most cases, this can produce acceptable results.