EGOTableViewPullRefresh动态刷新按钮

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


201308191346333282013081913463801520130819134642125


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

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



1
2
3
4
5
6
7
8
9
10
- ( 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、在ViewDidLoad方法中,修改背景图片,添加刷新按钮


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- ( 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、添加刷新按钮事件,和按钮旋转方法



1
2
3
4
5
6
7
8
9
10
11
12
//按钮旋转
- ( 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" ];
            
}



1
2
3
4
5
6
7
8
9
10
11
12
-( 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




     本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1284937,如需转载请自行联系原作者





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值