You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UIRefreshControl导致UICollectionView滚动时内容上跳问题求助

UICollectionView嵌入父ViewController时,UIRefreshControl下拉导致内容轻微向上跳动

我在使用UIRefreshControl时遇到了一个头疼的问题:当下拉滚动嵌入在另一个UIViewController中的UICollectionView时,它的内容会莫名出现轻微向上跳动的情况。问题的直观演示如下:

下拉刷新内容跳动演示

我已经翻遍了相关的问题讨论,但始终没找到适配我这个场景的解决方案。我的具体场景是把UICollectionViewController作为子视图嵌入到另一个UIViewController中,以下是我实现UIRefreshControl的代码:

let refreshControl = UIRefreshControl()
if #available(iOS 10.0, *){
    self.collectionView?.refreshControl = self.refreshControl
} else{
    self.collectionView?.insertSubview(self.refreshControl, at: 0)
}
self.collectionView?.alwaysBounceVertical = true
refreshControl.addTarget(self, action: #selector(refreshControlChanged), for: .valueChanged)
refreshControl.tintColor = UIColor.custom.blue.classicBlue

另外,我希望实现“用户停止拖拽后再触发数据刷新”的逻辑,相关代码如下:

@objc func refreshControlChanged(){
    if !(self.collectionView?.isDragging)!{
        nextRecommended()
    }
}

override func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    if refreshControl.isRefreshing{
        nextRecommended()
    }
}

nextRecommended()方法的具体实现:

DispatchQueue.main.async {
    self.refreshControl.endRefreshing()
    self.collectionView?.reloadData()
}

真心恳请各位能给我一些解决思路或可行的方案,非常感谢!

内容的提问来源于stack exchange,提问作者Phyber

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:39:10