quanguyen quanguyen - 29 days ago 16
iOS Question

swift 3 - UIRefreshControl not working in large screen

I have a

UICollectionView
in which I want to integrate a
UIRefreshControl
in order to enable user to swipe down to refresh.

Say I have 5 items in my
UICollectionView
. If I run my app in an iPhone5, then
UIRefreshControl
works beautifully. However, if I run it in an iPhone6Plus (where all 5 items are fit in screen), the
UIRefreshControl
just does not work any more; I even cannot swipe it down.

Is there any properties in
UIRefreshControl
that can help user to swipe down in any situations, no matter what size the screen is? I took a look at
UIRefreshControl
class below but it seems these cannot help:

public init()


open var isRefreshing: Bool { get }


open var tintColor: UIColor!

open var attributedTitle: NSAttributedString?


// May be used to indicate to the refreshControl that an external event has initiated the refresh action
@available(iOS 6.0, *)
open func beginRefreshing()

// Must be explicitly called when the refreshing has completed
@available(iOS 6.0, *)
open func endRefreshing()


An ugly solution is to make a refresh button, which I don't want.

You have any ideas?

Thanks in advance

Answer

That's because your collectionView's contentSize isn't large enough to scroll. (It's smaller than your screen size).

UIRefreshControl only works when your scrollView is scrollable.

If you would like to make your UICollectionView always scrollable.

Set the alwaysBounceVertical property to true. (Which is inherited by UIScrollView)