【问题标题】:How is the pull distance calculated for a UIRefreshControl如何计算 UIRefreshControl 的拉距
【发布时间】:2014-03-12 04:54:01
【问题描述】:

为了清楚起见,我不想改变距离,我只想知道它是什么,因为我同时在做一些其他的 UI 工作。是固定距离还是关联UITableView高度的函数?

【问题讨论】:

    标签: ios uitableview uirefreshcontrol


    【解决方案1】:

    拉距似乎非常接近tableView 高度的50%。

    仅供参考:您无法修改UIRefreshControl 的拉动距离。

    查看我的另一个answer 以获取替代方案。

    【讨论】:

      【解决方案2】:

      如果你想改变距离,你可以使用一个小技巧。 您可以通过一些修改使其正确

      lazy var refreshControl: UIRefreshControl = {
              let refreshControl = UIRefreshControl()
              refreshControl.tintColor = UIColor.red
              return refreshControl
          }()
      
      //refreshControl.addTarget(self, action: #selector(handleRefresh), for: .valueChanged)
      

      每个 PullToRefresh 都必须有几行这样的代码,handleRefresh 函数,做任何你需要刷新页面的事情。

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

      func scrollViewDidScroll(_ scrollView: UIScrollView) {
              if scrollView.contentOffset.y < -80 { //change 80 to whatever you want
                  if  !self.refreshControl.isRefreshing {
                      handleRefresh()
                  }
              }
          }
      

      我在 Ashkan Ghodrat 的回答的帮助下编写了这段代码

      【讨论】:

        猜你喜欢
        • 2013-12-11
        • 1970-01-01
        • 1970-01-01
        • 2022-06-14
        • 2015-10-07
        • 1970-01-01
        • 2012-12-04
        • 2013-03-18
        • 1970-01-01
        相关资源
        最近更新 更多