您好,登錄后才能下訂單哦!
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。