是否可以添加拖动以水平重新加载集合视图? [英] Is it possible to add a drag to reload horizontally for a collection view?

查看:25
本文介绍了是否可以添加拖动以水平重新加载集合视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于苹果文档中的以下行,我相信这可能是不可能的:

I belive it may not be possible given the folowing line in apples documentation:

当用户向下拖动可滚动内容区域的顶部时

When the user drags the top of the scrollable content area downward

在此处找到.

如果有办法做到这一点,请告诉我.

Let me know if there is a way to do this.

我试图做到这样,当用户在集合视图中向左滑动(在许多带有 tableViews 的应用程序中向上滑动以重新加载)时,它将显示一个加载图标并重新加载数据(重新加载数据部分我可以自己处理).

I am trying to make it so that when the user swipe left (the way you swipe up in many apps with tableViews to reload) in a collection view it will show a loading icon and reload data (the reload data part I can handle myself).

我怎样才能检测到这一点,以便我可以调用 reloadData() 方法?

How can I detect this so I can call a reloadData() method?

注意:我使用的 UICollectionView 只有一列和 x 行.在第一个单元格,如果用户向左滑动,它应该显示一个加载图标并重新加载数据.

Note: I am using a UICollectionView which only has one column and x rows. At the first cell if the user swipes left it should show a loading icon and reload data.

我正在寻找一种方法来检测要重新加载的左侧幻灯片.

I am looking for a way to detect the slide left intended to reload.

我尝试过的:

    let refreshControl = UIRefreshControl()

override func viewDidLoad() {
    super.viewDidLoad()
    viewDidLoadMethods()
    refreshControl.tintColor = .black
    refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged)
    collectionView.addSubview(refreshControl)
    collectionView.alwaysBounceHorizontal = true

但这仅适用于垂直方向.

But this only works vertically.

推荐答案

我用以下方法解决了这个问题,但我应该注意,没有像垂直刷新那样的默认功能:

I solved this problem with the following, but I should note that there is no default fucntionality like there is for vertical refresh:

 func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let offset = scrollView.contentOffset
    let inset = scrollView.contentInset
    let y: CGFloat = offset.x - inset.left
    let reload_distance: CGFloat = -80

    if y < reload_distance{
        shouldReload = true
    }
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    if let _ = scrollView as? UICollectionView {

        currentlyScrolling = false

        if shouldReload {
            baseVC.showReloading()
            reloadCollectionView()
        }
    }
 }

这篇关于是否可以添加拖动以水平重新加载集合视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆