EGOTableViewPullRefresh动态刷新按钮

发布时间:2020-06-14 18:37:11 作者:新风作浪
来源:网络 阅读:778

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


EGOTableViewPullRefresh动态刷新按钮EGOTableViewPullRefresh动态刷新按钮EGOTableViewPullRefresh动态刷新按钮


关于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




推荐阅读:
  1. 浅析:ListView的动态刷新问题
  2. iOS下拉刷新上拉加载更多EGOTableViewPullRefresh类库

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

egotableviewpullrefr 刷新按钮

上一篇:IOS比我们相像中的要“坚强”

下一篇:YAML数据格式学习

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》