具有低高度 UICollectionView 的 UIRefreshControl [英] UIRefreshControl with low height UICollectionView
问题描述
我有一个视图,其中包含顶部的另一个视图,我用它来显示一些基本信息.它大约占总视图高度的 40%.在该标题"视图下方,我使用的是可滚动的 UICollectionView.现在我已经向我的 UICollectionView 添加了一个 UIRefreshControl,但从未发生刷新,因为用户无法将 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. Below that "header" view, I'm using a UICollectionView which is scrollable. 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. When I reduce the height of the top view, it starts working because there's enough space to pull the collectionview down then.
这是我添加 refreshControl 的方法:
Here's how I'm adding the 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:
如您所见,UIRefreshControl 并未完全填满,而我的手指已经位于屏幕底部.
As you can see, the UIRefreshControl doesn't get fully filled, while my finger is already at the bottom of the screen.
我该如何解决?
推荐答案
你可以实现 scrollViewDidScroll.如果 scrollView 的 contentOffset 超过某个点,则使用 beginRefreshing() 以编程方式实现刷新
You can implement scrollViewDidScroll. If the scrollView's contentOffset is past a certain point, then implement your refresh programmatically using beginRefreshing()
例如(刷新控件连接到名为refreshControl"的插座)
eg (with the refresh control connected to an outlet named 'refreshControl')
func scrollViewDidScroll(scrollView: UIScrollView) {
let currentOffset = scrollView.contentOffset
let yOffset = currentOffset.y
if yOffset < -30.0 && !refreshControl.refreshing {
refreshControl.beginRefreshing()
}
}
如果您还没有设置滚动视图的委托,请不要忘记将其设置为 self
don't forget to set the scrollView's delegate to self if you haven't already
抱歉,是beginRefreshing(),而不是startRefreshing().
edit: sorry it's beginRefreshing(), not startRefreshing().
这篇关于具有低高度 UICollectionView 的 UIRefreshControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!