EGOTableViewPullRefresh Dynamic Refresh button

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.