UIScrollView: how could I recycle objects in my scrollable grid when the user scrolls?

I have a UIScrollView with a grid of images. Currently there are only 6 of them, but there may be several hundred. So, of course, it would be nice to create several hundred UIImageView objects inside this UIScrollView and fill them with all the image data. I think I read this somewhere in the Apple docs: they recommend creating only mutch elements like this since you need to fill the scrollable visible area.

But I'm scared of performance issues if I would move the UIImageView items instantly. I think. When the user starts scrolling down (let's assume it starts at 0,0), I'll have to move those UIView objects that go out of the visible area at the top, quickly positioning them down, and then assigning a very (!!) fast new image object to of this UIImageViews per line. I mean ... what if the user starts scrolling like a wild gazelle faster and faster?

How is your approach to this?

0


source to share


2 answers


On a similar, albeit finer scale, I dealt with this by loading more than I needed for the scroll sizes, but not for the entire dataset. I only scrolled horizontally and I found that loading 1 or 2 images on each side of the currently visible file remained nice and smooth. This still loads 3 or 5 images when only 1 is visible, but it's much better than loading dozens of them. You need to experiment a bit to see how many spalls you need to resolve around the visible area.



Dynamically loading / unloading images is best handled in scroll delegate methods.

+1


source


UIScrollView (or actually UIKit) is very good at not redrawing things that don't change. If you move (or remove rework) from the screen (or cropped) you won't redraw. Same thing with adding subViews from the screen.



If you don't have paging, you probably have to implement the faster drawing code that UIView offers. However, I would test first - the physical limitations of the iPhone are scrollable to some extent.

+1


source







All Articles