当sectionHeadersPinToVisibleBounds时,位于.top的indexPath处的scrollToItem隐藏标题下的单元格

Chr*_*her 4 uicollectionview uicollectionviewcell uicollectionviewlayout swift

使用以下配置:

let layout = UICollectionViewFlowLayout()
layout.sectionHeadersPinToVisibleBounds = true

let collectionViewController = UICollectionViewController(view.bounds, collectionViewLayout: layout)
Run Code Online (Sandbox Code Playgroud)

以下代码将滚动到给定的索引路径,但该项目将在其标题的下面并被其标题覆盖:

let indexPath = IndexPath(section: 0, row: 2)
collecitonView.scrollToItem(at: indexPath, at: .top, animated: true)
Run Code Online (Sandbox Code Playgroud)

将sectionHeadersPinToVisibleBounds设置为true时,如何使集合视图滚动到indexPath处的项目,而其项没有被其节头覆盖?

Rya*_*yan 5

似乎是iOS框架的错误。我正在用这种方式。

 guard let layout = collectionView.collectionViewLayout.layoutAttributesForItem(at: indexPath) else {
    collectionView.scrollToItem(at: indexPath, at: .top, animated: true)
    return
} 
let offset = CGPoint(x: 0, y: layout.frame.minY - headerHeight)
collectionView.setContentOffset(offset, animated: true)
Run Code Online (Sandbox Code Playgroud)