swift - 如何以编程方式删除 UICollectionView 部分页脚

标签 swift uicollectionview footer

我正在使用 UICollectionView 和包含事件指示器的部分页脚

在某些情况下我想删除或隐藏页脚

我用过这个方法,但效果不是100%

var footerView:FooterView!

...

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        switch kind {
        case UICollectionView.elementKindSectionFooter:
            footerView = collectionView.dequeueReusableSupplementaryView(
                ofKind: kind,
                withReuseIdentifier: "footer",
                for: indexPath) as? FooterView
            return footerView!
        default:
            assert(false, "Invalid element type")
        }
    }

以及隐藏页脚

self.footerView.alpha = 0

最佳答案

尝试实现高度方法

var show = false

func collectionView(_ collectionView: UICollectionView, 
                  layout collectionViewLayout: UICollectionViewLayout, 
 referenceSizeForFooterInSection section: Int) -> CGSize {
    return show ? CGSize(width:collectionView.frame.width,height:50) : CGSize.zero
}

更改变量并重新加载集合

关于swift - 如何以编程方式删除 UICollectionView 部分页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56045548/

相关文章:

ios - 当尝试从 Controller 更改该单元格中的 UITextField 时,UICollectionView 中的单元格返回 nil

javascript - jQuery Mobile 中的中心控制组

css - 粘性页脚中的垂直滚动条

ios - 如何使用 URL 参数和 UITableview 执行干净的 JSON 解码

swift - WatchKit (watchOS 2) CLLocationManager 返回零坐标

swift - ARKit 2.0 – 如何在两个 ARWorldMap 中组合 ARAnchors?

ios - reloadData() 不适用于 refreshControl

ios - 如何转换 NSUerdefaults AnyObject?到 SWIFT 阵列,以便我可以附加到它?

ios - 具有自动调整单元格的 Collection View 不再水平滚动

header - JQuery-Mobile内容区域的头部和 footer 之间的高度为100%