在屏幕外卸载UIImageView的图像 [英] Unload image of UIImageView thats offscreen

查看:98
本文介绍了在屏幕外卸载UIImageView的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ipad上编写应用程序,在我的应用程序的某个点上,我使用presentModalViewController呈现一个ViewController。

I'm coding an application on Ipad, in a certain point of my application I present a ViewController with the presentModalViewController.

我的ViewController是一个UISScrollView更大的modalView和里面我显示一些图像,我允许pagingEnabled所以我可以在scrollView中看到我的所有图像。

My ViewController is a UISScrollView who take the larger of the modalView and inside it I display some images, I allow pagingEnabled so I can see all my images inside the scrollView.

有时我必须显示10个以上的图像在scrollView中,所以我有这个错误
收到内存警告级别= 1 在这个接收内存警告级别= 2 之后并且由于信号导致调试器退出10(Sigbus)。

Sometimes I have to display more than 10 images inside the scrollView, so I have this error RECEIVE MEMORY WARNING LEVEL=1 after this one RECEIVE MEMORY WARNING LEVEL=2 and finnaly the debugger exited due to signal 10 (Sigbus).

我该怎么办?有没有办法卸载屏幕外的图像?或其他事情要做?

What can I do? is there a way to unload the image thats offscreen? or others things to do?

谢谢,

推荐答案

我猜您是要将所有图像添加到 UIScrollView 吗?然后iPad必须将所有10张图像保存在内存中。如果它们是全屏图像,则每个图像将占用大约3 MB的内存,因此您只需使用30 MB即可将10个图像保留在滚动视图中。

I guess you're adding all the images to the UIScrollView? Then the iPad has to keep all 10 images in memory. If they are full screen images, each of them will take up about 3 MB of memory, so you're using 30MB just to keep the 10 images in the scroll view.

您应该只添加实际可见的一个或两个图像。一旦它们滚出视线,从 UIScrollView 中删除​​ UIImageView (并确保不将其保留在任何地方)否则可以解除分配)。当新图像滚动到视线时,仅将其添加到 UIScrollView

You should only add the one or two images that are actually visible. Once they scroll out of sight, remove the UIImageView from your UIScrollView (and make sure you don't retain it anywhere else so it can be deallocated). When a new image scrolls into sight, add it to the UIScrollView only then.

在<$ c $中c> UIScrollViewDelegate 方法 -scrollViewDidScroll:获取当前的 contentOffset 并使用它来计算哪个图像可见。

In your UIScrollViewDelegate method -scrollViewDidScroll: get the current contentOffset and use that to calculate which images are visible.

这篇关于在屏幕外卸载UIImageView的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆