我的 xCode 项目中有一个 6000x3000 像素的图像,它位于可缩放 View 中。在初始 View 中,按下按钮以访问带有可缩放大图像的 View 。这一切都很好,除了“加载”图像所花费的时间经常导致应用程序崩溃,尤其是当我在旧设备上进行测试时(它似乎在我的 4G itouch 上大部分时间都可以正常工作) .有没有办法“预渲染”这个大图像,或者我可以做些什么来防止崩溃?
最佳答案
算一下:6000 x 3000 x 3(红绿蓝)= 54,000,000 字节 = 51.5MiB 的原始数据。正常的图像处理有很多开销,而且只会占用太多内存。
根据this question解决方案是使用 CATiledLayer。据我了解,您需要将您的大图像分成更小的部分,并在 CATiledLayer 的帮助下绘制这些更小的部分。
编辑:这是 UIView 类引用的引用:
Note: In iOS 2.x, the maximum size of a UIView object is 1024 x 1024 points. In iOS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. It is in your best interests to keep view sizes as small as possible. Regardless of which version of iOS is running, you should consider tiling any content that is significantly larger than the dimensions the screen.
阅读:如果较大,请使用 CATiledLayer 绘制较小的部分。
关于iphone - 大图像导致 xCode 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5134584/