【问题标题】:iOS How to Implement UITableView Bottom Refresh Control [duplicate]iOS如何实现UITableView底部刷新控件[重复]
【发布时间】:2015-04-24 04:08:46
【问题描述】:

我只是想知道是否有一种方法可以在没有任何第三方库的情况下使用 UIRefreshControl 来实现底部刷新控件。

提前致谢。

【问题讨论】:

  • 不,这不是 UIRefreshControl 的自定义选项。如果您确定没有刷新控件动画,您可以设置您的表格以在它滚动到底部时刷新其数据。
  • 这应该是你要找的:stackoverflow.com/questions/14942460/…

标签: ios objective-c uitableview swift uirefreshcontrol


【解决方案1】:

您可以将页脚添加到表格视图部分,设置刷新视图,使用func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?,如果页脚加载然后调用下一个设置刷新动画之类的东西。

可以用这种方式解决你的问题。

HTH,享受编码!

【讨论】:

  • 我相信这是合乎逻辑的简单解决方案,无需重新发明轮子。并且应该被所有搜索底部刷新的人关注。真的不明白为什么要让自己复杂化使用滚动视图这种解决方案,这可能会在某些边缘情况下添加意外行为。
【解决方案2】:

好吧,过了一段时间,有了上面所有的 cmets 和答案,我想出了一些东西。

使用 scrollViewDidScroll 我实现了底部刷新

如果 UIScrollView 已到达底部,它会向上滑动 UIView,并在执行后自动向下滑动并重新加载 UITableView。

scrollViewDidScroll 函数

 func scrollViewDidScroll(scrollView: UIScrollView) {
    let scrollOffset : CGFloat = scrollView.contentOffset.y
    let scrollHeight : CGFloat = scrollView.frame.size.height

    let scrollContentSizeHeight : CGFloat = scrollView.contentSize.height + scrollView.contentInset.bottom

    let tableFrame : CGRect = self.tableView.frame

    if (scrollOffset + scrollHeight) >= scrollContentSizeHeight {
        self.bottomRefreshAnimation()
    } else {
        if self.tableView.frame.origin.y < 0 {
            UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                self.tableView.frame.origin.y = self.tableView.frame.origin.y + 40
                }, completion: nil)
        }
    }
}

self.bottomRefreshAnimation() 包含从底部为 UIView 设置动画的代码

 func bottomRefreshAnimation(){
    if self.tableView.frame.origin.y > 0 {

        UIView.animateWithDuration(0.4, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
            self.tableView.frame.origin.y = self.tableView.frame.origin.y - 40
            }, completion: nil)

        populateData({ (finished) -> () in
            UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                    if self.tableView.frame.origin.y < 0 {
                        self.tableView.frame.origin.y = self.tableView.frame.origin.y + 40
                    }
                }, completion: nil)
        })
    }
}

最重要的是它检查 UITableView Origin.y 并在 UIView 向上滑动时将大小减小 40。

希望对大家有所帮助 如果有更好的方法来实现这一点,请告诉我

感谢大家的回复。

【讨论】:

    【解决方案3】:

    这应该是您要查找的内容:UIRefreshControl at the bottom of the UITableView iOS6?

    您还可以使用以下方法刷新 tableView 的任何行:

    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-06
      • 2012-10-13
      • 2015-09-21
      • 1970-01-01
      • 2015-01-27
      • 2015-08-01
      • 2014-11-27
      • 1970-01-01
      相关资源
      最近更新 更多