一个下拉刷新的iOS控件,具有玩乒乓球的效果。
安装
可以通过CocoaPods安装。将 pod ‘BOZPongRefreshControl’ ?加入到你的Podfile。
另外,只要把 BOZPongRefreshControl.h ?和 BOZPongRefreshControl.m ?放到你项目的任意位置就好了。
使用方式
将它与 UITableView ?和 UIScrollView ?绑定,如下:
- (void)viewDidLoad
{
[super viewDidLoad];
/* NOTE: Do NOT attach the refresh control in viewDidLoad!
* If you do this here, it'll act very funny if you have
* a navigation bar or other such similar thing that iOS
* automatically offsets content for. You have to wait for
* the subviews to get laid out first so the refresh
* control knows how big that offset is!
*/
}
- (void)viewDidLayoutSubviews
{
self.pongRefreshControl = [BOZPongRefreshControl attachToTableView:self.tableView
withRefreshTarget:self
andRefreshAction:@selector(refreshTriggered)];
}
然后,将 UIScrollViewDelegate ?在你的 UIViewController ?中实现,然后将调用通过指导控制器刷新。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.pongRefreshControl scrollViewDidScroll];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
[self.pongRefreshControl scrollViewDidEndDragging];
}
最后,保证早已实现 refreshAction ?然后使它通过,继而监听刷新目标:
- (void)refreshTriggered
{
//Go and load some data
//Finshed loading the data, reset the refresh control
[self.pongRefreshControl finishedLoading];
}