I have collection view inside a table view.
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
}
}
}