GTMRefresh
github地址
简书地址
GTMRefresh
用Swift重写的MJRefresh
Introduction
- 自定义方便, Demo里面有国内主流App的下拉效果的模仿
- 代码简洁,总代码量不超过1000行
- 支持国际化
- 支持: UITableView, UICollectionView, UIScrollView, UIWebView
Demo
直接下载代码,里面Demo里面有各种效果的自定义效果(因为时间比较紧,demo代码可能不够漂亮)
Demo模仿的下拉效果
- YahooWeather
- Curve Mask
- Youku
- TaoBao
- QQ Video
- DianPing
Installation
Cocoapods
Install Cocoapods if need be.
$ gem install cocoapods
Add GTMRefresh
in your Podfile
.
use_frameworks!pod 'GTMRefresh'
Then, run the following command.
$ pod install
Manual
Copy GTMRefresh
folder to your project. That’s it.
Note: Make sure that all files in GTMRefresh
included in Compile Sources in Build Phases.
版本
Vesrion 0.0.1
This version requires Xcode 8.0 and Swift 3.
使用帮助
Firstly, import GTMRefresh
.
import GTMRefresh
使用默认的下拉和上拉效果
self.tableView.gtm_addRefreshHeaderView {[weak self] inprint("excute refreshBlock")self.refresh()}self.tableView.gtm_addLoadMoreFooterView {[weak self] inprint("excute loadMoreBlock")self.loadMore()}
代码触发刷新
self.tableView.triggerRefreshing()
自定义下拉刷新效果
约定
- 必须继承 GTMRefreshHeader
- 必须实现 SubGTMRefreshHeaderProtocol
SubGTMRefreshHeaderProtocol
public protocol SubGTMRefreshHeaderProtocol {/// 状态变成.idlefunc toNormalState()/// 状态变成.refreshingfunc toRefreshingState()/// 状态变成.pullingfunc toPullingState()/// 状态变成.willRefreshfunc toWillRefreshState()/// 下拉高度/触发高度 值改变func changePullingPercent(percent: CGFloat)/// 开始结束动画前执行func willBeginEndRefershing(isSuccess: Bool)