溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

EGOTableViewPullRefresh動態(tài)刷新按鈕

發(fā)布時間:2020-06-14 18:37:11 來源:網(wǎng)絡(luò) 閱讀:791 作者:新風(fēng)作浪 欄目:開發(fā)技術(shù)

EGOTableViewPullRefresh 是fork EGOTableViewPullRefresh開源類庫進(jìn)行的改進(jìn),添加了上提加載更多效果。同時也可以通過一個按鈕的觸發(fā)刷新事件,但是刷新的時候不能跳到top,為了動態(tài)展示,再刷新的時候按鈕旋轉(zhuǎn),然后跳轉(zhuǎn)回到頂部!如下如圖


EGOTableViewPullRefresh動態(tài)刷新按鈕EGOTableViewPullRefresh動態(tài)刷新按鈕EGOTableViewPullRefresh動態(tài)刷新按鈕


關(guān)于EGOTableViewPullRefresh可以參照http://blog.csdn.net/duxinfeng2010/article/details/9007311,翻譯過的用法,在這個Demo基礎(chǔ)上進(jìn)行修改,點(diǎn)擊Demo下載;

1、給工程添加一個導(dǎo)航欄,在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、添加刷新按鈕事件,和按鈕旋轉(zhuǎn)方法



//按鈕旋轉(zhuǎn)
- (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是否處于刷新狀態(tài),如果沒有則執(zhí)行本次刷新
    if (!self.pullTableView.pullTableIsRefreshing) {
        self.pullTableView.pullTableIsRefreshing = YES;
//        設(shè)置回到top時候table的位置
        [self.pullTableView setContentOffset:CGPointMake(0, -60) animated:YES];
        [self performSelector:@selector(refreshTable) withObject:nil afterDelay:3.0];
    }
                 
}



×××地址:https://github.com/XFZLDXF/RefreshButtonDemo




向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI