EGOTableViewPullRefresh 是fork EGOTableViewPullRefresh开源类库进行的改进,添加了上提加载更多效果。同时也可以通过一个按钮的触发刷新事件,但是刷新的时候不能跳到top,为了动态展示,再刷新的时候按钮旋转,然后跳转回到顶部!如下如图




关于EGOTableViewPullRefresh可以参照http://blog.csdn.net/duxinfeng2010/article/details/9007311,翻译过的用法,在这个Demo基础上进行修改,点击Demo下载;

1、给工程添加一个导航栏,在application: didFinishLaunchingWithOptions:方法中



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // Override point for customization after application launch.// [[UINavigationBar appearance] setBackgroundImage:[UIImage p_w_picpathNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.viewController]; self.window.rootViewController = nav; [self.window makeKeyAndVisible]; return YES;}



2、在ViewDidLoad方法中,修改背景图片,添加刷新按钮


- (void)viewDidLoad{ [super viewDidLoad]; self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[UIImage p_w_picpathNamed:@"navbar.png"]]; self.pullTableView.pullArrowImage = [UIImage p_w_picpathNamed:@"blackArrow"];// self.pullTableView.pullBackgroundColor = [UIColor yellowColor]; self.pullTableView.pullTextColor = [UIColor blackColor]; CGRect rect = CGRectMake(0, 0, 44, 44); UIButton *refreshBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; refreshBtn.frame = rect; [refreshBtn setBackgroundImage:[UIImage p_w_picpathNamed:@"button_refresh"] forState:UIControlStateNormal]; [refreshBtn addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithCustomView:refreshBtn]; self.navigationItem.leftBarButtonItem = refreshItem; }



3、添加刷新按钮事件,和按钮旋转方法



//按钮旋转- (void)startAnimation:(UIButton *)button{ CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; [rotate setByValue:[NSNumber numberWithFloat:M_PI*4]]; rotate.duration = 3.0; rotate.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [button.layer addAnimation:rotate forKey:@"myRotationAnimation"]; }



-(void)refresh:(UIButton *)button{ [self startAnimation:button];// 判断一下table是否处于刷新状态,如果没有则执行本次刷新 if (!self.pullTableView.pullTableIsRefreshing) { self.pullTableView.pullTableIsRefreshing = YES;// 设置回到top时候table的位置 [self.pullTableView setContentOffset:CGPointMake(0, -60) animated:YES]; [self performSelector:@selector(refreshTable) withObject:nil afterDelay:3.0]; } }


×××地址:https://github.com/XFZLDXF/RefreshButtonDemo