节省空间:首次启动时批量缩小旧 iPhone/iPad/iPod 的所有 @2x 图像大小
与此有关的问题: iPhone 4 - 加载图像 x 旧设备
我们最终会填充我们的应用程序具有双重内容,即用户必须将 2 倍大小和 1 倍大小的图像下载到他的设备上,但最终只会使用其中之一,而另一个将浪费下载时间等。
所以我想,在某些情况下,只需用高分辨率图像(@2x)填充您的应用程序就可以了,并且在应用程序启动时(在应用程序委托中,在显示窗口之前...或其他内容),您可以批量缩放所有@对于低分辨率屏幕设备,图像缩小 2 倍。缩小后,您可以将这些文件保存到设备的文档和/或缓存文件夹中,并删除原始的 @2x 图像。怎么样,有人已经这样做了吗?这有什么缺点吗? Apple 会因为我这样做而在某个地方打我吗? ETC。
The issue with this:
iphone 4 - loading images x old devices
Is that we end up filling our apps with double content, i.e., a user has to download both the 2x size and the 1x sized image to his device, but will eventually only use one of them and the other one will be a waste of download time etc.
So I thought, in some cases it could be okay with just filling your app with the high res images (@2x), and on app launch (in the app delegate, before displaying the window... Or something), you could batch scale all @2x images down for low res screen devices. When scaled down, you save those files to the device's documents and/or cache folder, and delete the original @2x images. How about that, did anyone do it already? Any downsides to this? Will Apple smack me somewhere for doing this? etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您绝对可以批量缩放这些 @2x 图像并将缩放后的文件保存到文档文件夹中。这将节省下载时间,并使用与将所有内容与应用程序捆绑在一起相同的空间,但代价是增加一些复杂性。然而,我认为删除原始的 @2x 图像是不可能的,即使是,也不值得——有可能在设备之间移动应用程序和用户数据。一旦同时拥有这两个数据,最好根据分辨率选择正确的数据。我不认为苹果有什么理由因为你的行为而惩罚你。
哦,当然,如果您确实有大量数据,大约数百兆字节,那么制作两个版本的应用程序可能是有意义的(例如,与 Rage 类似)。
You definitely could batch scale those @2x images and save the scaled files to the documents folder. That would save download time, and use the same amount of space as bundling everything with your application, at the cost of some added complexity. I don't think that deleting the original @2x images is possible, however, or worth it even if it were - there's the possibility of moving apps and user data between devices. It would be the best just to choose the right data based on resolution, once you have them both. And I don't see much reason for Apple to smack you for doing this.
Oh, and of course, if you really have a lot of data, in the order of hundreds of megabytes, doing two versions of the app might make sense (in the vein of Rage, for example).
我暂时回答一下我的想法。
进行批处理时,您必须将图像保存到缓存/文档文件夹或类似的文件夹中。这意味着,低分辨率设备仍然无法找到 IB 中指定的任何图像,可能使用普通的 imageNamed 等也找不到它们(对此还不确定)。可能是解决这个问题的方法,或者我可能不得不在 viewDidLoad 中手动添加图像。闻起来很乱。可能会工作,有一个好的解决方案...
应用程序更新可能会很麻烦。由于应用程序更新发布速度很慢(对不起苹果,是的,更新发布速度很慢)。通过更新,您可能希望擦除缓存文件夹,以确保通过更新更改/删除的旧图像不会仍然留在缓存中。缓存需要通过某种版本控制进行监督。例如检查当前应用程序版本,以及该版本是否已完成缓存。如果没有,请刷新缓存,有点流程。
I'm gonna answer my thoughts for now.
when doing a batch, you have to save the images to the cache/documents folder or something like that. Which means, any image specified in IB will still not be found by low res devices, possibly they won't be found with using the normal imageNamed etc either (not sure about this yet). Might be a fix for this, or I might have to fiddle with adding the images manually in viewDidLoad. Smells messy. Might work, with a good solution...
might be troublesome with app updates. As app updates are slow to publish (sorry Apple, yes, updates are slow to publish). With an update you probably would want to erase the cache folder, to make sure old images that were changed/removed with the update aren't still lingering in the cache. The caching would need to be supervised with some kind of versioning. Like check current app version, and if caching has been done for this version. If not, refresh the cache, kind of flow.