UIRefreshControl - 集合视图在滚动时跳转

时间:2018-01-20 13:57:46

标签: ios swift uicollectionview uirefreshcontrol

我对UIRefreshControl有疑问。当我向下滚动collectionView时,collectionView的内容会略微上升。

GIF:https://imgur.com/a/8rK5s

我已经看到了一些关于这个确切问题的问题,但是,我还没有找到一个适合我的答案。 (例如this question

我在另一个UICollectionViewController内有一个UIViewCotroller作为子视图。

我已经像这样实施了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

此外,我希望我的collectionView在用户停止拖动后刷新数据。

@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()
}

任何帮助都非常感激。

0 个答案:

没有答案
相关问题