I've been digging through the "new" compositional layout api introduced in iOS 13, hoping to find a solution to the contrived approach of embedding a UITableView
inside a UICollectionViewCell
.
I have used this headache-inducing solution in the past in order to provide horizontal page scrolling with vertical table scrolling at the same time. It is a very cumbersome way of doing things and ever since CompositionalLayout
was announced I have been dying to give a shot at refactoring it.
So far, no luck. I can make the horizontal scrolling and the vertical scrolling work, but can't get past the "App Store" behaviour where each line scrolls horizontally in an independent way. Has anyone had any luck implementing a similar solution?
This is my code for the CollectionViewLayout
:
func createOrthogonalScrollingLayout() -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(0.5))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .groupPagingCentered
section.interGroupSpacing = 16
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)
let layout = UICollectionViewCompositionalLayout(section: section)
return layout
}
This produces a vertical scroll of two items and a horizontal scroll which shows the remaining items in the subsequent pages, but only two per page. My goal is to have the "pages" divided by days of the year and each one should have X number of items which are vertically scrollable.
Thank you