ios – Tips on how to appropriately scroll UICollectionView to a particular part header which have estimated supplementary view top?


My UICollectionView has a number of sections and has lengthy checklist of things with supplementary header views. I must animate to a particular part and present the part header within the view port. Tried to search out the placement of the part header utilizing greatest appropriate method like beneath however due to the header views have completely different top than estimated preliminary worth, the end result shouldn’t be right. The layoutAttributesForSupplementaryElement makes use of estimated top when the part shouldn’t be seen and inflicting fallacious location for contentOffset calculation:

if let sectionHeaderPosition = collectionView.layoutAttributesForSupplementaryElement(
                ofKind: DocType.reuseIdentifier, 
                at: .init(merchandise: 0, part: part)
            ) {
                let offsetY = sectionHeaderPosition.body.origin.y -
               collectionView.setContentOffset(CGPoint(x: 0, y: offsetY), animated: true)

Any strategies?