ios基于MJRefresh实现上拉刷新和下拉加载动画效果

本文介绍了ios基于MJRefresh实现上拉刷新和下拉加载动画效果,分享给大家,具体如下:

目录

1、 头部刷新动画

2、尾部刷新动画

头部刷新动画

#import <MJRefresh/MJRefresh.h>

@interface HZNormalHeader : MJRefreshGifHeader

@end

#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;

}

实现部分

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];

});

}];

尾部刷新动画

#import <MJRefresh/MJRefresh.h>

@interface XZZNormalFooter : MJRefreshAutoGifFooter

@end

#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

实现部分

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];

});

}];

以上是 ios基于MJRefresh实现上拉刷新和下拉加载动画效果 的全部内容, 来源链接: utcz.com/z/348353.html

回到顶部