How Do I Shorten the Pull Distance on UIRefreshControl to Activate the Pull to Refresh Action?
you can still use refreshControl but with some modifications!
add these code to your viewController:
var canRefresh = true
override func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentOffset.y < -100 { //change 100 to whatever you want
if canRefresh && !self.refreshControl.refreshing {
self.canRefresh = false
self.refreshControl.beginRefreshing()
self.refresh() // your viewController refresh function
}
}else if scrollView.contentOffset.y >= 0 {
self.canRefresh = true
}
}
and as usual in the end of your refresh logic in self.refresh() function add :
self.refreshControl.endRefreshing()
As per the Apple Docs, I don't see any way to modify UIRefreshControl
parameters.
link: https://developer.apple.com/library/ios/documentation/uikit/reference/UIRefreshControl_class/Reference/Reference.html
Use a third-party component like ODRefreshControl (to customize the scroll-distance in order to activate the refresh, modify the #define kMaxDistance
constant).
or...
Don't use the UIRefreshControl
and instead implement your own logic in the -scrollViewDidScroll
method like:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height) {
//refresh logic
}
}