EGOTableViewPullRefresh is an improvement of the fork EGOTableViewPullRefresh open source class library. You can also use a button to trigger a refresh event, but you cannot jump to the top when refreshing. For dynamic display, the button is rotated when refreshing, and then jumps back to the top! As follows:
650) this. width = 650; "src =" http://img.blog.csdn.net/20130819134633328 "_ xhe_src =" http://img.blog.csdn.net/20130819134633328 "style =" max-width: 98%; "/> 650) this. width = 650; "src =" http://img.blog.csdn.net/20130819134638015 "_ xhe_src =" http://img.blog.csdn.net/20130819134638015 "style =" max-width: 98%; "/> 650) this. width = 650; "src =" http://img.blog.csdn.net/20130819134642125 "_ xhe_src =" http://img.blog.csdn.net/20130819134642125 "style =" max-width: 98%; "/>
For details about EGOTableViewPullRefresh, refer to callback;
1. Add a navigation bar to the project. In application: didfinishlaunchingwitexceptions: method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // Override point for customization after application launch.// [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.viewController]; self.window.rootViewController = nav; [self.window makeKeyAndVisible]; return YES;}
2. In the ViewDidLoad method, modify the background image and add the refresh button.
- (void)viewDidLoad{ [super viewDidLoad]; self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"navbar.png"]]; self.pullTableView.pullArrowImage = [UIImage imageNamed:@"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 imageNamed:@"button_refresh"] forState:UIControlStateNormal]; [refreshBtn addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithCustomView:refreshBtn]; self.navigationItem.leftBarButtonItem = refreshItem; }
3. Add refresh button events and button rotation methods
// Button rotation-(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]; // checks whether the table is refreshed. if not, execute this refresh if (! Self. pullTableView. pullTableIsRefreshing) {self. pullTableView. pullTableIsRefreshing = YES; // set the position of the table to [self. pullTableView setContentOffset: CGPointMake (0,-60) animated: YES]; [self defined mselector: @ selector (refreshTable) withObject: nil afterDelay: 3.0];}
Source code: https://github.com/XFZLDXF/RefreshButtonDemo
This article from the "fresh wind wave" blog, please be sure to keep this source http://duxinfeng.blog.51cto.com/3911492/1284937