Implementation of Pinterest Gridview on iOS

I want to implement a grid similar to that on Pinterest

I was thinking of implementing in the form of three tabular views. But I could not scroll them well. When I implemented scrollViewDidScroll and set contentOffset to be viewed by tables with different scrolling, scrolling became slow and unusable.

Another implementation that I did was that I had a set of images to load and call the viewDraw function in scrollViewDidScroll . The ViewDraw function simply draws the necessary images and deletes the rest of the images from the already allocated memory, but will not be visible. it also slows down ScrollView scrolling. And another problem is that white (background colors) patches are drawn in front of the images.

What should be the best way to implement this grid view?

+4
source share
1 answer

Solution 1 (I don't know if this works, and I don't like it very much)

How about three vertical table views next to each other, but forward any touch events from any kind of table to others. I understand that when you tried to synchronize table views, you had performance problems, but perhaps working on an event-level situation will work better. May be.

Decision 2

Use UIScrollView (for scrolling purposes, of course). For performance and memory reasons, you also need to implement an on-demand download mechanism so that you do not download all your images at once.

To do this, I would create a class, CustomImageStrip, which processes a vertical list of images. This class works with scrollview and uses contentOffset to decide when it is time to load / unload an image from the strip.

With 3 independent image band classes, images can be of any size and do not need to be aligned. But, since they all belong to the same UIScrollView, scrolling will be performed simultaneously.

+3
source

Source: https://habr.com/ru/post/1396181/


All Articles