How to configure UIRefreshControl to make descending height lower than the default

In UIRefreshControl in an iOS app, I think it’s set by default that when I pull out the UITableView (UISrollView) at about “100px”, the update starts.

I would like to make the above value smaller (like "50px")

Is it possible?

If possible, please tell me code samples.

+4
source share
1 answer

Try the following:

// definition
extension UIRefreshControl {
    func refreshManually() {
        beginRefreshing()
        sendActions(for: .valueChanged)
    }
}

// usage
var isRefreshingManually = false
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView.contentOffset.y < -80.0 {
        if !isRefreshingManually && !refreshControl.isRefreshing {
            isRefreshingManually = true
            refreshControl.refreshManually()
        }
    } else if scrollView.contentOffset.y >= 0 {
        isRefreshingManually = false
    }
}

My sample code is for UICollectionView, but UITableView and UIScollView work too.

Replace "-80.0" in my code with what you need.

0
source

All Articles