捆绑很多 images/icons

Bundle a LOT of images/icons

在捆绑包中包含大量图像的最佳方式是什么?我有一个(游戏)项目的索引,因此大约有 4000-5000 个图像文件(总共 27mb,所以不是那么大)。只需将整个地图包含在捆绑包中,或者先编写一个将它们转换为 NSData 的脚本?我可以想象会有一种聪明的方法来做到这一点,这样应用程序就不必单独查看所有图像来找到单个图像。很想听听你的想法。

27mb 的下载量并不大,因此最简单的选择是将它们放入资产目录中,因为 Ryan Heitner mentioned in his comment this will allow App Thinning 将在 iOS 9.

中进行

我不确定你的意思:

I could imagine there would be a smart way to do this so the app wouldn't have to look through all images individually to find a single one

每张图片都需要有一个唯一的名称(无论您拥有多少资产都是如此)并且您的代码通过该名称引用图片,因此它不必 "look through all images individually to find a single one"。

或者,如果您真的想减少初始下载大小,您可以使用 On Demand Resources (another upcoming iOS 9 feature) to store them on Apple servers and loaded on demand in your code. Presumably you won't be targeting only iOS 9 though so in this case you would need to host the resources yourself and load them using standard techniques (see here, here, here, or use a library

您应该将它们打包成 texture atlas

然后,纹理图集文件应该通过文件夹引用(蓝色文件夹图标)而不是组(黄色文件夹图标)导入到您的捆绑包中。

文件夹引用中捆绑导入的图像不会在打包时优化 Xcode。因此,您可以使用 imageOptim 进行自己的文件优化。它可以比 Xcode 对 JPEG 和 PNG 图像压缩更多。