iphone - 大图像导致 xCode 崩溃

标签 iphone xcode image ios uiimageview

我的 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/

相关文章:

ios - 如何在 Swift 和 Xcode 6 中使用不同的 api url 进行暂存和生产

ios - 快速扫描存储在 Xcode 项目中的目录内容

具有多个过滤器的图像搜索

iphone - iPhone 4.3 Tableview 中的多个单元格选择

ios - HMCharacteristicWriteAction 为 targetValue 传递什么

ios - 导出到 Delphi XE2 中缺少的 Xcode

html - div 中的图像在图像下方有额外的空间

iphone - 关于申请批准的问题

ios - 自定义选项卡栏上的“更多”菜单

javascript - 使用 ruby​​ on rails 和 javascript 将 Canvas 转换为图像并在新窗口中打开