我做了一个UIRefreshControl:

refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "refresh")
refresher.addTarget(self, action: "refreshed", forControlEvents: UIControlEvents.ValueChanged)
refresher.addTarget(self, action: "refreshed", forControlEvents: UIControlEvents.ApplicationReserved)
refresher.addTarget(self, action: "refreshed", forControlEvents: UIControlEvents."scrolled down to bottom")

这是一个刷新器,可以正常工作,但是我想添加一个动作,当我向下滚动到tableView的底部时将使其刷新,就像对ValueChanged所做的一样,但对于底部

最佳答案

您可以使用内置的scrollViewDidEndDecelerating

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    let bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height
    if bottomEdge >= scrollView.contentSize.height {
        // Reached bottom, do your refresh
        print("Bottom")
    }
}

scrollView结束时,它正在减速,并且您位于底部,那么您可以调用refresher

关于ios - addTarget到UIRefreshControl(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34613785/

10-15 15:27