当 sectionHeadersPinToVisibleBounds 时,位于 .top indexPath 的 scrollToItem 隐藏标题下的单元格 [英] scrollToItem at indexPath at .top hides cell under header when sectionHeadersPinToVisibleBounds

查看:29
本文介绍了当 sectionHeadersPinToVisibleBounds 时,位于 .top indexPath 的 scrollToItem 隐藏标题下的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下配置:

let layout = UICollectionViewFlowLayout()
layout.sectionHeadersPinToVisibleBounds = true

let collectionViewController = UICollectionViewController(view.bounds, collectionViewLayout: layout)

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

The following code will scroll to the given index path but the item will be under and covered by its header:

let indexPath = IndexPath(section: 0, row: 2)
collecitonView.scrollToItem(at: indexPath, at: .top, animated: true)

当 sectionHeadersPinToVisibleBounds 设置为 true 时,如何让集合视图滚动到 indexPath 处的项目,而该项目不会被其节标题覆盖?

How do I get the collection view to scroll to the item at indexPath without the item being covered by its section header when sectionHeadersPinToVisibleBounds is set to true?

推荐答案

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

It seems like a iOS framework's bug. I'm using this way.

 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)

这篇关于当 sectionHeadersPinToVisibleBounds 时,位于 .top indexPath 的 scrollToItem 隐藏标题下的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆