i use collectionView with compositional layout and diffableDataSource collectionview cells are self sizing.
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
currentSection = indexPath.row
if let attributes = allCollectionView.collectionViewLayout.layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: currentSection)) {
let bottomOffset = CGPoint(x: 0, y: allCollectionView.bottomOffsetY)
let offset = CGPoint(x: 0, y: attributes.frame.origin.y)
chipCollectionView.selectItem(at: indexPath, animated: true, scrollPosition: .left)
if attributes.frame.origin.y > bottomOffset.y {
allCollectionView.setContentOffset(bottomOffset, animated: false)
} else {
allCollectionView.setContentOffset(offset, animated: false)
}
}
}
i use this code and The issue goes away once I begin scrolling around and trigger cell reuse/recomputation of layout (I suppose).
In this code, the position when setContentoffSet is executed is showing the row lists rather than the section above, and setContentOffset cannot find the correct position until the cell is reused, perhaps due to the effect of a dynamic cell. Has anyone experienced this problem?