tableview 行中集合视图的同步水平滚动 [英] Synchronized horizontal scrolling of collection views in tableview rows

查看:18
本文介绍了tableview 行中集合视图的同步水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在表视图中的所有集合视图中同步滚动(请参阅下面的图片链接):

I'm trying to synchronize scrolling in all collection views within a table view (see image link below) :

示例图片:http://postimg.org/image/dduhr89e5/

我找到的示例说明了如何通过识别每个视图来同步两个单独的滚动视图.但是,我不确定如何在表视图中识别每个集合视图.可能有 1 个或数百个都需要同步.

The sample that I have been able to find explains how you can sync two separate scroll views by identifying each. However I am unsure how to identify each collection view when they are in a table view. There could be 1 or hundreds that all need synchronized.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
  if ([scrollView isEqual: theFirstScrollView])
  {
        theSecondScrollView.contentOffset =
              CGPointMake(theFirstScrollView.contentOffset.x, 0);
  }
  else
  {
        theFirstScrollView.contentOffset = 
              CGPointMake(theSecondScrollView.contentOffset.x, 0);
  }
}

推荐答案

假设每个集合视图都有自己的单元格并且集合视图的宽度相似(或者至少您已经弄清楚了那部分),这是我会采用的方法使用:

Assuming each collection view has its own cell and the collection views are similar widths (or at least you have that part figured out), here is the approach I would use:

1) 让您的 VC 成为所有集合视图的代表.

1) Make your VC the delegate for all of the collection views.

2) 当它们中的任何一个滚动时,遍历 TableViews visibleCells 并设置单元格 collectionView 的内容偏移量.另外,将内容偏移量存储在 viewController 中.

2) When any of them scrolls, go through the TableViews visibleCells and set the content offset for the cells collectionView. Also, store the content offset in the viewController.

3) 每当新单元出列时,将内容偏移量设置为 VC 中最后存储的值.

3) Whenever a new cell is dequeued, set the content offset to that last stored value in the VC.

这篇关于tableview 行中集合视图的同步水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆