本文介绍了ios基于MJRefresh实现上拉刷新和下拉加载动画效果,分享给大家,具体如下:
目录
1、 头部刷新动画
2、尾部刷新动画
头部刷新动画
1
2
3
4
5
|
#import <MJRefresh/MJRefresh.h> @interface HZNormalHeader : MJRefreshGifHeader @end |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#import "HZNormalHeader.h" @implementation HZNormalHeader #pragma mark - 重写父类的方法 - ( void )prepare{ [super prepare]; // 设置普通状态的动画图片 NSMutableArray *idleImages = [NSMutableArray array]; for (NSUInteger i = 1; i<=60; i++) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@ "dropdown_anim__000%zd" , i]]; [idleImages addObject:image]; } [self setImages:idleImages forState:MJRefreshStateIdle]; // 设置即将刷新状态的动画图片(一松开就会刷新的状态) NSMutableArray *refreshingImages = [NSMutableArray array]; for (NSUInteger i = 1; i<=3; i++) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@ "dropdown_loading_0%zd" , i]]; [refreshingImages addObject:image]; } [self setImages:refreshingImages forState:MJRefreshStatePulling]; // 设置正在刷新状态的动画图片 [self setImages:refreshingImages forState:MJRefreshStateRefreshing]; //隐藏时间 self.lastUpdatedTimeLabel.hidden = NO; //隐藏状态 self.stateLabel.hidden = NO; } |
实现部分
1
2
3
4
5
6
|
self.tableView.mj_header = [HZNormalHeader headerWithRefreshingBlock:^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.tableView.mj_header endRefreshing]; }); }]; |
尾部刷新动画
1
2
3
4
5
|
#import <MJRefresh/MJRefresh.h> @interface XZZNormalFooter : MJRefreshAutoGifFooter @end |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#import "XZZNormalFooter.h" @implementation XZZNormalFooter #pragma mark - 重写父类的方法 - ( void )prepare{ [super prepare]; // 设置普通状态的动画图片 NSMutableArray *idleImages = [NSMutableArray array]; for (NSUInteger i = 1; i<=60; i++) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@ "dropdown_anim__000%zd" , i]]; [idleImages addObject:image]; } [self setImages:idleImages forState:MJRefreshStateIdle]; // 设置即将刷新状态的动画图片(一松开就会刷新的状态) NSMutableArray *refreshingImages = [NSMutableArray array]; for (NSUInteger i = 1; i<=3; i++) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@ "dropdown_loading_0%zd" , i]]; [refreshingImages addObject:image]; } [self setImages:refreshingImages forState:MJRefreshStatePulling]; // 设置正在刷新状态的动画图片 [self setImages:refreshingImages forState:MJRefreshStateRefreshing]; //隐藏时间 // self.lastUpdatedTimeLabel.hidden = NO; /*隐藏*/ self.refreshingTitleHidden = YES; //隐藏状态 self.stateLabel.hidden = YES; } @end |
实现部分
1
2
3
4
5
|
self.tableView.mj_footer = [XZZNormalFooter footerWithRefreshingBlock:^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.tableView.mj_footer endRefreshing]; }); }]; |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://www.jianshu.com/p/332e68dc3540?utm_source=tuicool&utm_medium=referral