简体   繁体   English

具有低高度的UIRefreshControl UICollectionView

[英]UIRefreshControl with low height UICollectionView

I have a view which contains another view on the top part, which I'm using to show some basic information. 我有一个视图,该视图在顶部包含另一个视图,用于显示一些基本信息。 It has about 40% of the total view height. 它占总视图高度的40%。 Below that "header" view, I'm using a UICollectionView which is scrollable. 在该“标题”视图下,我使用的是可滚动的UICollectionView。 Now I've added a UIRefreshControl to my UICollectionView, but refreshing does never occur, because the user can't pull down the UICollectionView that far. 现在,我已将UIRefreshControl添加到我的UICollectionView中,但是刷新从未发生过,因为用户无法将UICollectionView拉到那么远。 When I reduce the height of the top view, it starts working because there's enough space to pull the collectionview down then. 当我减小顶视图的高度时,它开始工作,因为那时有足够的空间将collectionview下拉。

Here's how I'm adding the refreshControl: 这是我添加refreshControl的方法:

    self.matchDetailRefreshControl = UIRefreshControl()
    self.matchDetailRefreshControl.addTarget(self, action: #selector(MatchDetailViewController.fetchAll), forControlEvents: .ValueChanged)
    self.collectionView!.addSubview(self.matchDetailRefreshControl)
    self.collectionView!.alwaysBounceVertical = true

Have a look at this screenshot for reference: 请看以下屏幕截图以供参考: 在此处输入图片说明

As you can see, the UIRefreshControl doesn't get fully filled, while my finger is already at the bottom of the screen. 如您所见,UIRefreshControl并未完全填充,而我的手指已经在屏幕底部。

How can I fix that? 我该如何解决?

You can implement scrollViewDidScroll. 您可以实现scrollViewDidScroll。 If the scrollView's contentOffset is past a certain point, then implement your refresh programmatically using beginRefreshing() 如果scrollView的contentOffset已超过某个点,则使用beginRefreshing()以编程方式实现刷新

eg (with the refresh control connected to an outlet named 'refreshControl') 例如(将刷新控件连接到名为“ refreshControl”的插座)

func scrollViewDidScroll(scrollView: UIScrollView) {

    let currentOffset = scrollView.contentOffset

    let yOffset = currentOffset.y

    if yOffset < -30.0 && !refreshControl.refreshing {
        refreshControl.beginRefreshing()
    }
}

don't forget to set the scrollView's delegate to self if you haven't already 如果您还没有忘记将scrollView的委托设置为self,

edit: sorry it's beginRefreshing(), not startRefreshing(). 编辑:对不起,它是beginRefreshing(),而不是startRefreshing()。

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

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