Home > Net >  Scroll all collection view cell inside table view
Scroll all collection view cell inside table view

Time:07-18

I have collection view inside a table view.

It looks like a spreadsheet:enter image description here

Collection view scrolls horizontally and table view vertically. I want all the collection view to scroll at once.

Can anyone help me with the solution?

CodePudding user response:

    protocol CollectionViewScrollDelegate{
    func didScrollCollectionView(contentOffset: CGPoint)
}

    extension CellTableView : UIScrollViewDelegate{
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if delegate != nil{
            delegate?.didScrollCollectionView(contentOffset: collectionView.contentOffset)
        }
    }
}

        var requiredContentOffset:CGPoint!

    extension MyVC : CollectionViewScrollDelegate{
    func didScrollCollectionView(contentOffset: CGPoint) {
        requiredContentOffset = contentOffset
        let cells = tblView.visibleCells as! Array<CellTableView>
        for cell in cells {
            cell.collectionView.contentOffset = contentOffset
        }
    }
}

extension MyVC : UIScrollViewDelegate{
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let cells = tblView.visibleCells as! Array<CellTableView>
        for cell in cells {
            cell.collectionView.contentOffset = requiredContentOffset
        }
    }
}
  • Related