我在我的项目中有一个要求,当UICollectionView头变得粘滞时,我必须向它们添加阴影。
我正在使用UICollectionViewFlowLayout节HeadersPinToVisibleBounds上的属性,当设置为YES时,它会使标题具有粘性。
当标题变得粘滞并实际固定到顶部时,我们是否可以获得某种回调,以便我可以向该标题添加阴影?我不希望当一个头不粘的时候有阴影。
这里的挑战是,我不能真正利用method- layoutAttributesForSupplementaryView中的信息:它确实为我提供了屏幕上的视图,因为我的部分具有动态的项目数,因此屏幕上的哪个部分并没有真正告诉我谁需要阴影。
2条答案
按热度按时间goucqfw61#
我通过以下方法找到了这个问题的答案:
1.手动保存表头位置:
我使用的是viewWithPosition元组
var viewWithPosition = [(name: String, position: CGFloat)]()
的数组。如果我只保存单元格的位置,情况可能是一样的,但由于我的单元格有不同的文本,我使用name
参数来检查元素是否已经存在于数组中。我使用了helper函数:1.当我有初始位置时,我检查可见标题是否放错了位置:
}
目前,苹果似乎没有为这种情况提供任何回调。希望这也是你的解决方案。
dw1jzc5e2#
我对IvanMih的解决方案进行了现代化和改进。请注意,
headerGroupsBeingDisplayed
是在UICollectionView
中显示的数据集: