开发者

iphone: a way to optimize image loading on scrollview.

In my app, I display images with scrollview. I avoid memory issue by adding view as user scroll through. Scrolling seems fine but it stop in split second when new image is loaded on next/pervious view. I tried to load image on NSThread but no performance wa开发者_开发知识库s improved.

I use [UIImage imageWithData:] to load image. I wonder if there is a way to load an image more efficient way. It would be appreciated for any comments regard this issue.


I think the best way is to keep three pictures at once in memory: the picture on the current screen, the picture on the next screen and the picture on the previous screen. By doing this you can scroll smoothly. You can use your imageWithData method with this procedure.

It gets even simpler if you use imageNamed instead, because this method caches the pictures if it has enough memory. So you just have to load the current picture and the next picture by just calling

[UIImage imageNamed:@"nextPic"];

By executing this, it loads the picture into the cache but does not display it. The next time you have to display the picture it is already in memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜