提问人:Austin Huang 提问时间:11/16/2023 最后编辑:Austin Huang 更新时间:11/17/2023 访问量:78
UICollectionView.scrollToItem(at:at:animated:) 在 IOS 17 上将该部分滚动到视图之外
UICollectionView.scrollToItem(at:at:animated:) scroll the section out of view on IOS 17
问:
我发现有时调用会在 IOS 17 设备和带有 Xcode 14 的 Mac OS 15 上滚动到一个奇怪的地方,在 IOS 17 设备(IOS 16...UICollectionView.scrollToItem(at:at:animated:)
下面是一个案例:应用视图
这是我的设置:
private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
view.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
let collectionLayoutConfig = UICollectionViewCompositionalLayoutConfiguration()
collectionLayoutConfig.scrollDirection = .horizontal
let layout = UICollectionViewCompositionalLayout(sectionProvider: { section, _ in
func getSection(cellCount: Int, extraInterGroupSpacing: Bool = false) -> NSCollectionLayoutSection {
let cellSpacing = 10
let cellInset = 24
let cellLength = UICollectionView.cellLength(cellCount: cellCount, colViewLength: TT.screenWidth,
cellSpacing: cellSpacing, inset: cellInset)
let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(cellLength), heightDimension: .absolute(cellLength))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(cellLength))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
group.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
group.interItemSpacing = NSCollectionLayoutSpacing.fixed(10)
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 24,
bottom: extraInterGroupSpacing ? 30 : 24,
trailing: 24)
section.interGroupSpacing = extraInterGroupSpacing ? 20 : 10
section.orthogonalScrollingBehavior = .continuous
return section
}
switch section {
case 0:
return getSection(cellCount: 7)
case 1:
return getSection(cellCount: 4, extraInterGroupSpacing: true)
default:
return getSection(cellCount: 4)
}
}, configuration: collectionLayoutConfig)
collectionView.setCollectionViewLayout(layout, animated: true)
collectionView.showsHorizontalScrollIndicator = false
collectionView.register(cellType: CutoutCell.self)
collectionView.register(cellType: CutoutCellAnimated.self)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = .clear
collectionView.contentInsetAdjustmentBehavior = .automatic
collectionView.isPagingEnabled = true
我打电话将内容滚动到中心,它过度向上滚动。scrollToItem(at: indexPath, at: .centeredVertically, animated: true)
有没有人遇到过类似的问题?
它不应该过度滚动。
更新:
我发现套装可以解决这个问题。collectionView.isPagingEnabled = false
答: 暂无答案
上一个:如何在iOS中更改状态栏文本颜色
下一个:如何消除堆叠在一起的弹出窗口?
评论
scrollToItem