繁体   English   中英

是否可以在 CollectionView 的 Header 中放置 Refresh Controller?

[英]Is it possible to put a Refresh Controller in the Header of CollectionView?

我有一个带有HeaderCollectionView ,我想将RefreshController添加到我已经做过的CollectionView中。 正如我所期望的那样,它显示在Header上方 但是我希望RefreshController显示Header中。

原因是Toolbar覆盖了 Header。 当我下拉刷新时, Header以我希望RefreshController可见的方式可见。 但是我必须拉低Header的高度才能使RefreshController可见,即
a) 滚动距离过大和
b) RefreshControllerCollectionView之间的空间太大

这是一些代码:

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
    super.viewDidLoad()

    [...]

    refreshControl.tintColor = .gray
    refreshControl.backgroundColor = .white
    refreshControl.addTarget(self, action: #selector(refreshContents), for: .valueChanged)
    eventCollectionView.refreshControl = refreshControl
    eventCollectionView.register(EventHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: toolbarId)
}

@objc func refreshContents() {
    self.perform(#selector(finishedRefreshing), with: nil, afterDelay: 1.5)
}

@objc func finishedRefreshing() {
    refreshControl.endRefreshing()
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    return .init(width: screenWidth, height: 50)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM