EGOTableViewPullRefresh 是fork EGOTableViewPullRefresh開源類庫進行的改進,添加了上提加載更多效果。同時也能夠經過一個按鈕的觸發刷新事件,可是刷新的時候不能跳到top,爲了動態展現,再刷新的時候按鈕旋轉,而後跳轉回到頂部!以下如圖git
關於EGOTableViewPullRefresh能夠參照http://blog.csdn.net/duxinfeng2010/article/details/9007311,翻譯過的用法,在這個Demo基礎上進行修改,點擊Demo下載;github
一、給工程添加一個導航欄,在application: didFinishLaunchingWithOptions:方法中app
- (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; }
二、在ViewDidLoad方法中,修改背景圖片,添加刷新按鈕ide
- (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; }
|
三、添加刷新按鈕事件,和按鈕旋轉方法spa
//按鈕旋轉 - (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]; } }