Synchronized horizontal scrolling of collection views in tableview rows

喜你入骨 提交于 2019-12-23 00:30:55

问题


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

Example Image : http://postimg.org/image/dduhr89e5/

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);
  }
}

回答1:


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) Make your VC the delegate for all of the collection views.

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) Whenever a new cell is dequeued, set the content offset to that last stored value in the VC.



来源:https://stackoverflow.com/questions/25983373/synchronized-horizontal-scrolling-of-collection-views-in-tableview-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!