ESPullToRefresh
ESPullToRefresh是一個非常易于開發(fā)者使用的下拉刷新和加載更多組件。通過一個UIScrollView的擴展,可以輕松為UIScrollView的所有子類添加下拉刷新功能。 如果你想定制組件的UI樣式,只要實現(xiàn)指定的協(xié)議方法即可。Github地址
如何安裝
使用CocoaPods
pod "ESPullToRefresh"
手動安裝
git clone https://github.com/eggswift/37122.html">swift/pull-to-refresh.gitopen ESPullToRefresh
開始使用
使用默認樣式 效果如下:

設置默認下拉刷新組件
self.tableView.es_addPullToRefresh { [weak self] in /// 在這里做刷新相關事件 /// ... /// 如果你的刷新事件成功,設置completion自動重置footer的狀態(tài) self?.tableView.es_stopPullToRefresh(completion: true) /// 設置ignoreFooter來處理不需要顯示footer的情況 self?.tableView.es_stopPullToRefresh(completion: true, ignoreFooter: false) })}設置默認加載更多組件
self.tableView.es_addInfiniteScrolling { [weak self] in /// 在這里做加載更多相關事件 /// ... /// 如果你的加載更多事件成功,調(diào)用es_stopLoadingMore()重置footer狀態(tài) self?.tableView.es_stopLoadingMore() /// 通過es_noticeNoMoreData()設置footer暫無數(shù)據(jù)狀態(tài) self?.tableView.es_noticeNoMoreData() })}使用自定義樣式 效果如下:

注: 加載動畫資源來自美團 iOS app。

ESPullToRefresh通過ESRefreshProtocol和ESRefreshAnimatorProtocol來約束刷新組件的使用,自定義的組件必須遵守這兩個協(xié)議,并實現(xiàn)協(xié)議中的方法。
設置自定義下拉刷新組件
func es_addPullToRefresh(animator animator: protocol<ESRefreshProtocol, ESRefreshAnimatorProtocol>, handler: ESRefreshHandler)
設置自定義加載更多組件
func es_addInfiniteScrolling(animator animator: protocol<ESRefreshProtocol, ESRefreshAnimatorProtocol>, handler: ESRefreshHandler)
移除方法
func es_removeRefreshHeader()func es_removeRefreshFooter()
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點
疑難解答