开发者

Memory question: photo gallery using UIImageView, NSArray & SwipeGesture vs UIScrollview

I am developing an App for iphone and the same for iPad - the core of it is a photo gallery. I want to be able to show up to 80 full screen images one-by-one, with a slide left or right function.

I know I can either do this using UIImageView with an NSArray and SwipeGesture, but it can also be achieved using UIScrollview.

Quick question - which 开发者_StackOverflow社区way uses least memory, or releases the images efficiently from the memory once they've been viewed?

Any help appreciated.

Also, is there a youtube or online step-by-step tutorial that shows how to do a UIScrollView in this context?

Thanks!


In terms of using the least amount of memory, either way you're going to have to use a swapping method so you only have 2-3 images in memory at any one time. I've found using much more than that will quickly hit the limit of the device.

I would use a UIScrollView, because it will feel more natural. If you use a SwipeGesture then the user won't be able to move the current image to the left/right slightly and get the nice rubber band effect. (Well, you could reproduce it with the UIGestureRecognizer but it would take a lot more work). Spend some time with the built in Photos app to see what I mean. Pull an image to the left/right without letting go and you can see the image next to it.

Also, don't forget if you want to allow zooming on each image as well as swiping to the next/previous one.

For a tutorial to get you started, see here: http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html. Should be enough to get you started.


The efficiency is dependent on how you handle your images. Compared to that, the efficiency of swapping UIImageViews based on a swipe gesture versus a paged UIScrollView containing UIImageViews is vanishingly small.

It'll be up to you to keep the memory footprint of UIImages to a minimum. Practically, this might mean loading up one or two images to either side of the currently displayed UIImage at times when you decided it is appropriate, and releasing more distant ones that may have been previously loaded. If you want to go the swipe gesture route, this time would be when you detect the swipe gesture. If you go for the paged UIScrollView route, one of the UIScrollViewDelegate methods would be a great place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜