Ios 如何缩短UIRefreshControl上的拉动距离以激活拉动刷新操作?

Ios 如何缩短UIRefreshControl上的拉动距离以激活拉动刷新操作?,ios,uitableview,uiwebview,uirefreshcontrol,Ios,Uitableview,Uiwebview,Uirefreshcontrol,大家好 我已经试着解决这个问题一段时间了,但是没有用,我需要一些帮助。我的应用程序底部有一个UITableView,屏幕距离不够,用户无法进行刷新。是否有人知道如何缩短在UITableView和UIWebView中的UIRefreshControl上激活“拉入刷新”操作所需的距离 提前谢谢大家 根据Apple文档,我看不到任何修改UIRefreshControl参数的方法。 链接: 使用第三方组件,如(要自定义滚动距离以激活刷新,请修改#define kMaxDistance常量) 或 不要使用

大家好

我已经试着解决这个问题一段时间了,但是没有用,我需要一些帮助。我的应用程序底部有一个
UITableView
,屏幕距离不够,用户无法进行刷新。是否有人知道如何缩短在
UITableView
UIWebView
中的
UIRefreshControl
上激活“拉入刷新”操作所需的距离


提前谢谢大家

根据Apple文档,我看不到任何修改
UIRefreshControl
参数的方法。
链接:

使用第三方组件,如(要自定义滚动距离以激活刷新,请修改
#define kMaxDistance
常量)

或 不要使用
UIRefreshControl
,而是在
-scrollViewDidScroll
方法中实现自己的逻辑,如:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height) {
        //refresh logic
    }
}

您仍然可以使用refreshControl,但需要进行一些修改

将以下代码添加到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
    }
}

你可以做一些修改使它正确

lazy var refreshControl: UIRefreshControl = {
        let refreshControl = UIRefreshControl()
        refreshControl.tintColor = UIColor.red
        return refreshControl
    }()

//refreshControl.addTarget(self, action: #selector(handleRefresh), for: .valueChanged)
每个PullToRefresh都必须有两行这样的代码,即HandlerRefresh函数,执行刷新页面所需的任何操作

您只需要注释掉addTarget行并将此函数添加到代码中 ```

func scrollViewDidScroll(scrollView:UIScrollView){
如果scrollView.contentOffset.y<-80{//将80更改为您想要的任何值
if!self.refreshControl.isRefreshing{
handleRefresh()
}
}
}

我在Ashkan Ghodrat回答Swift 3.2及以上版本的帮助下编写了这段代码:

var canRefresh = true

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView.contentOffset.y < -100 {
        if canRefresh && !self.refreshControl.isRefreshing {
            self.canRefresh = false
            self.refreshControl.beginRefreshing()
            self.handleRefresh()
        }
    } else if scrollView.contentOffset.y >= 0 {
        self.canRefresh = true
    }
}
var canRefresh=true
func scrollViewDidScroll(scrollView:UIScrollView){
如果scrollView.contentOffset.y<-100{
如果可以刷新&!self.refreshControl.isRefreshing{
self.canRefresh=false
self.refreshControl.beginRefreshing()
self.handleRefresh()
}
}否则,如果scrollView.contentOffset.y>=0{
self.canRefresh=true
}
}

是否有影响牵引距离的可修改参数?我看着它,但没有看到任何东西。或者我可能只是瞎了眼,今天有一个可怕的隧道视力。@DanielSanchez:我还没有必要修改它。无论如何,这可能会有帮助:@DanielSanchez aah,在
ODRefreshControl.m
中修改
#define kMaxDistance 53
参数。我想那会对你有帮助的先生你是个天才!谢谢!我相信这是解决任何人试图做同样的事情我正在做的。我只是使用并修改了
#define kMaxDistance 53
常量,以获得所需的输出。呜呼!现在看来这个答案是错的,伙计们。正如Ashkan所解释的,你可以直接调用.beginRefreshing()。太棒了!非常感谢。这正是我希望找到的。感谢canRefresh hack。refreshcontrol大小在没有它的情况下随机更改。显然,这应该是选定的答案!!你可能在找这个
func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView.contentOffset.y < -80 { //change 80 to whatever you want
            if  !self.refreshControl.isRefreshing {
                handleRefresh()
            }
        }
    }
var canRefresh = true

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView.contentOffset.y < -100 {
        if canRefresh && !self.refreshControl.isRefreshing {
            self.canRefresh = false
            self.refreshControl.beginRefreshing()
            self.handleRefresh()
        }
    } else if scrollView.contentOffset.y >= 0 {
        self.canRefresh = true
    }
}