I have a UICollectionViewController
inside of a UINavigationController
and when the collection view does not contain any data, I want to have a single item that fills the visible area of the collection view.
I'm using UICollectionViewCompositionalLayout
and thought I would be able to do this with a group / item size that has a fractionalWidth
and fractionalHeight
of 1.0
like this:
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
let layout = UICollectionViewCompositionalLayout(section: section)
However, this does not respect the collection view's safe area insets, so the item is too tall and ends up scrolling:
Is there a way to have the fractionalHeight
take the collection view's safe area into account or some other way to have a single item that fills the collection view's safe area?