Pinterest Gridview 在 iOS 上的实现
我想实现一个类似于 Pinterest 中的网格视图
我考虑过实现为 3 个表格视图。但我无法将它们很好地滚动在一起。当我实现 scrollViewDidScroll
并为除 scrollView 之外的表视图设置 contentOffset
时,滚动变得缓慢且无法使用。
我所做的另一个实现是加载一组图像并调用 scrollViewDidScroll
中的 viewDraw 函数。 ViewDraw 函数只是绘制必要的图像,并从内存中删除已绘制但不可见的其余图像。 这也会使 ScrollView 滚动缓慢。另一个问题是在绘制图像之前存在白色(背景色)色块。
实现此网格视图的最佳方法应该是什么?
I want to implement a grid view like the one in Pinterest
I thought about implementing as 3 table views. But I was not able to scroll them together well. When I implemented the scrollViewDidScroll
and set the contentOffset
for the table views other the scrollView , the scrolling became slow and unusable.
Another implementation I did was of was having a set of images to load and calling the viewDraw function in scrollViewDidScroll
. The ViewDraw
function just draws the necessary images and removes the rest of the images from the memory which were already drawn but wont be visible .
this too makes the ScrollView scrolling slow. And another issue with it is that there are white(background color) patches before the images are drawn.
What should be the best way to implement this grid view ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案 1 (我不知道这是否有效,而且我不太喜欢它)
如何并排放置 3 个垂直表格视图,但将任何触摸事件从任何表格视图转发到另一个表格视图那些。我知道您在尝试同步表格视图时遇到了性能问题,但也许在事件级别上工作会更好。或许。
解决方案 2
使用 UIScrollView(当然是为了滚动)。出于性能和内存方面的原因,您还需要实现按需加载机制,这样您就不会一次加载所有图像。
为此,我将创建一个类 CustomImageStrip 来处理垂直图像列表。该类与滚动视图一起工作,并使用
contentOffset
来决定何时从条带加载/卸载图像。通过拥有 3 个独立的图像条带类,图像可以是任意大小并且不需要对齐。但是,由于它们都属于同一个 UIScrollView,因此滚动将同时完成。
Solution 1 (i don't know if this works and I don't like it very much)
How about having 3 vertical table views side by side, but forward any touch events from any tableview to the other ones. I understand that you had performance problems when trying to sync the tableviews, but maybe working on an event level things would work better. Maybe.
Solution 2
Use a UIScrollView (for the scrolling purposes of course). For performance and memory reasons you also need to implement a load-on-demand mechanism so that you don't load all your images at once.
To do this I would create a class, CustomImageStrip that handles a vertical image list. This class works together with the scrollview and uses
contentOffset
to decide when it is time to load/unload a image from the strip.By having 3 independent image strip classes, the images can be of any size and don't need to be aligned. But, since they all belong to the same UIScrollView the scrolling will be done simultaneously.