我知道这已经被问了很多次,但是我现在无法找到适当的解决方案,尽管我已经挖了很长时间。
我有一个带有标题的集合视图。
我想在标题和主集合视图之间留一个空格。
我尝试实现如下的插图:
@objc(collectionView:layout:insetForSectionAtIndex:) override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets{
print("called insetForSectionAt with a section value of: \(section)")
if ( section == 1 ) {return UIEdgeInsetsMake(100, 0, 0, 0)}
else {return UIEdgeInsetsMake(0, 0, 0, 0) }
}
得到以下内容:
called insetForSectionAt with a section value of: 0
called insetForSectionAt with a section value of: 0
called insetForSectionAt with a section value of: 0
called insetForSectionAt with a section value of: 0
called insetForSectionAt with a section value of: 0
called insetForSectionAt with a section value of: 0
很明显这样做什么都没有,ow可以为主集合视图设置插图而不是整个屏幕本身?如果我使用100作为index0的顶部插入,这会影响标题,这不是我需要的。
感谢。