UICollectionViewScrollPosition.top hides under header

I need a sticky header so in ViewDidLoad I set,


let layout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout
     layout?.sectionHeadersPinToVisibleBounds = true


Then I have a button that scrolls the UICollectionViewCell to the top using


//todayIndexpath is and IndexPath set from cellForRowAt
if let indexP = todayIndexpath {
            collectionView?.scrollToItem(at: indexP, at: UICollectionViewScrollPosition.top, animated: true)
        }


unfortunately the cell that scrolls to the top also goes behind the section header. so it sis obstructed. I need to scroll so the cell at the indexpath scrolls to the top but underneath the header. Would have thought that UICollectionViewScrollPosition.top would take into account the header as when the view first loads its underneath it so must know its there.

Is there a fix?

Replies

Did you find the solution for this issue?