ESPullToRefresh
ESPullToRefresh是一個(gè)非常易于開發(fā)者使用的下拉刷新和加載更多組件密幔。通過(guò)一個(gè)UIScrollView的擴(kuò)展,可以輕松為UIScrollView的所有子類添加下拉刷新功能撩轰。 如果你想定制組件的UI樣式胯甩,只要實(shí)現(xiàn)指定的協(xié)議方法即可。 Github地址
如何安裝
使用CocoaPods
pod "ESPullToRefresh"
手動(dòng)安裝
git clone https://github.com/eggswift/pull-to-refresh.git
open ESPullToRefresh
開始使用
使用默認(rèn)樣式 效果如下:
設(shè)置默認(rèn)下拉刷新組件
self.tableView.es_addPullToRefresh {
[weak self] in
/// 在這里做刷新相關(guān)事件
/// ...
/// 如果你的刷新事件成功堪嫂,設(shè)置completion自動(dòng)重置footer的狀態(tài)
self?.tableView.es_stopPullToRefresh(completion: true)
/// 設(shè)置ignoreFooter來(lái)處理不需要顯示footer的情況
self?.tableView.es_stopPullToRefresh(completion: true, ignoreFooter: false)
})
}
設(shè)置默認(rèn)加載更多組件
self.tableView.es_addInfiniteScrolling {
[weak self] in
/// 在這里做加載更多相關(guān)事件
/// ...
/// 如果你的加載更多事件成功偎箫,調(diào)用es_stopLoadingMore()重置footer狀態(tài)
self?.tableView.es_stopLoadingMore()
/// 通過(guò)es_noticeNoMoreData()設(shè)置footer暫無(wú)數(shù)據(jù)狀態(tài)
self?.tableView.es_noticeNoMoreData()
})
}
使用自定義樣式 效果如下:
注: 加載動(dòng)畫資源來(lái)自美團(tuán) iOS app。
ESPullToRefresh
通過(guò)ESRefreshProtocol
和ESRefreshAnimatorProtocol
來(lái)約束刷新組件的使用皆串,自定義的組件必須遵守這兩個(gè)協(xié)議淹办,并實(shí)現(xiàn)協(xié)議中的方法。
設(shè)置自定義下拉刷新組件
func es_addPullToRefresh(animator animator: protocol<ESRefreshProtocol, ESRefreshAnimatorProtocol>,
handler: ESRefreshHandler)
設(shè)置自定義加載更多組件
func es_addInfiniteScrolling(animator animator: protocol<ESRefreshProtocol, ESRefreshAnimatorProtocol>,
handler: ESRefreshHandler)
移除方法
func es_removeRefreshHeader()
func es_removeRefreshFooter()
如果在使用中有什么疑問(wèn)恶复,可以隨時(shí)@我