Reputation: 414
I have a collection view obove and a table view below. What I want to do is, when I scroll down the table view, I want to take along the collection view.
This time, the collection view does not move when I scroll the table view.
Thanks in advance for your little help!
Upvotes: 2
Views: 135
Reputation: 149
1.) You could set the tableView.tableHeaderView to be your collection view.
2.) The second solution is that can also use the UITableViewDelegate's method viewForHeaderInSection and return your collection view. Don't forget to also implement the heightForHeaderInSection method. For this to work you also have to set the table view's style to grouped. This can be done in the storyboard.
Upvotes: 0
Reputation: 110
If you want to scroll down the collection view put the collection view inside the table view. In this case both will be scrolled down if you scroll down the table view
Upvotes: 4
Reputation: 459
You could use the UIScrollViewDelegate
's method scrollViewDidScroll(_:)
.
Your view controller should look like this:
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == tableView {
collectionView.contentOffset = scrollView.contentOffset // or f(scrollView.contentOffset)
}
}
}
Upvotes: 0