2

I created a UICollectionView using the CompositionalLayout and DiffableDatasource APIs. Everything works and looks as expected, except for the Orthogonal ScrollView that is shifted upwards.

The following screenshot shows the relevant portion of my view hierarchy. The highlighted view is the UICollectionViewOrthogonalScrollerEmbeddedScrollView which as you can see seems to have the correct size, but not the correct position along the y-axis.

View Hierarchy Snapshot

Besides the scrolling gestures being recognised in the wrong area of the layout, the button in the header element above is not accessible as it's obstructed by said scrollView.

Here is the definition of my NSCollectionLayoutSection:

            let fractionalGroupWidth: CGFloat = 0.85
            
            //Define Item Size
            let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(60))
            let item1 = NSCollectionLayoutItem(layoutSize: itemSize, supplementaryItems: [UICollectionView.getSeparatorSupplementaryItem(ofKind: "Separator1", withLeadingOffset: 72, forAbsoluteWidth: self.collectionView.frame.width*fractionalGroupWidth)])
            let item2 = NSCollectionLayoutItem(layoutSize: itemSize, supplementaryItems: [UICollectionView.getSeparatorSupplementaryItem(ofKind: "Separator2", withLeadingOffset: 72, forAbsoluteWidth: self.collectionView.frame.width*fractionalGroupWidth)])
            let item3 = NSCollectionLayoutItem(layoutSize: itemSize)
            
            //Define Group Size
            let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(fractionalGroupWidth), heightDimension: .estimated(180))
            let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item1, item2, item3])
            group.interItemSpacing = .fixed(12)
            
            let section = NSCollectionLayoutSection(group: group)
            section.contentInsets = NSDirectionalEdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16)
            section.interGroupSpacing = 16
            section.orthogonalScrollingBehavior = .groupPaging
            
            if sectionData.title != nil || sectionData.shortTitle != nil{
                let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(40))
                let headerElement = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
                section.boundarySupplementaryItems = [headerElement]
            }
            
            return section

I've tried changing the height dimensions for the individual items as well as the groups from fractional values to estimated or absolute values and also tried adjusting the contentInsets. None of the above had any effect on the scrollView.

Medwe
  • 318
  • 1
  • 12

0 Answers0