Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CopyVIEW部分不考虑页眉/页脚视图_Ios_Swift_Uicollectionview_Uicollectionreusableview_Uicollectionviewflowlayout - Fatal编程技术网

Ios CopyVIEW部分不考虑页眉/页脚视图

Ios CopyVIEW部分不考虑页眉/页脚视图,ios,swift,uicollectionview,uicollectionreusableview,uicollectionviewflowlayout,Ios,Swift,Uicollectionview,Uicollectionreusableview,Uicollectionviewflowlayout,我有一个带有页眉和页脚的collectionView。我想在节的末尾添加间距 我正在使用: func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return UIEdgeInsets(top: 0, left: 0, b

我有一个带有页眉和页脚的collectionView。我想在节的末尾添加间距

我正在使用:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
    return UIEdgeInsets(top: 0, left: 0, bottom: 16, right: 0)
}

但是,这并不考虑页脚视图。因此,插入部分被添加到该节的最后一个索引中。在应用插图之前,是否有任何方法或方式包含节页脚

我需要页脚视图下的插图

optional func collectionView(_ collectionView: UICollectionView, 
viewForSupplementaryElementOfKind kind: String, 
                          at indexPath: IndexPath) -> UICollectionReusableView
现有功能的说明。(黄色是indexPath.item)预期的功能是在页脚下插入(红色)


正如您正确指出的,UICollectionView的部分位于页眉和页脚之间

如果要在页脚下方添加间距,最好的方法是创建自定义页脚视图

optional func collectionView(_ collectionView: UICollectionView, 
viewForSupplementaryElementOfKind kind: String, 
                          at indexPath: IndexPath) -> UICollectionReusableView
是此方法的文档

理想情况下,您希望为自定义页脚创建一个子类:]

class CustomFooterView: UICollectionReusableView {

}
然后,在
viewDidLoad
中注册它:

collectionView.register(CustomFooterView.self, forSupplementaryViewOfKind: .elementKindSectionFooter, withReuseIdentifier: "Your footer reuse ID")
然后,您可以按如下方式返回:

override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    if kind == UICollectionView.elementKindSectionFooter {
        return collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Your footer reuse ID", for: indexPath)
    }
    else {
    }
}
现在您只需要确保自动布局能够确定页脚的大小。因此,将标签添加到自定义页脚,并确保其底部约束等于所需的填充

注意:有一个警告。既然您实现了返回自定义页脚的方法,并且对页眉调用了相同的方法,那么您可能还需要使用自定义页眉。或者,您需要注册标准的UICollectionReusableView,并为您的标题定义它