时间:2020-10-10 22:23:38 | 栏目:iOS代码 | 点击:次
本文主要介绍iOS 利用MJRefresh实现自定义动画的上拉刷新下拉加载效果,一般的类型(包括更新时间与loading图案)这里不做介绍.
要想实现此功能,首先得有一套load的图片数组.
接下来就是实现过程:
引入头文件:
#import "MJRefresh.h" //自定义一个方法实现 - (void)prepareRefresh { NSMutableArray *headerImages = [NSMutableArray array]; for (int i = 1; i <= 4; i++) { UIImage *image = [UIImage imageNamed:[NSStringstringWithFormat:@"topload%d",i]]; [headerImages addObject:image]; } MJRefreshGifHeader *gifHeader = [MJRefreshGifHeaderheaderWithRefreshingBlock:^{ //下拉刷新要做的操作. }]; gifHeader.stateLabel.hidden = YES; gifHeader.lastUpdatedTimeLabel.hidden = YES; [gifHeader setImages:@[headerImages[0]]forState:MJRefreshStateIdle]; [gifHeader setImages:headerImages forState:MJRefreshStateRefreshing]; _tableView.header = gifHeader; NSMutableArray *footerImages = [NSMutableArray array]; for (int i = 1; i <= 4; i++) { UIImage *image = [UIImage imageNamed:[NSStringstringWithFormat:@"footerload%d",i]]; [footerImages addObject:image]; } MJRefreshAutoGifFooter *gifFooter = [MJRefreshAutoGifFooterfooterWithRefreshingBlock:^{ //上拉加载需要做的操作. }]; gifFooter.stateLabel.hidden = YES; gifFooter.refreshingTitleHidden = YES; [gifFooter setImages:@[footerImages[0]]forState:MJRefreshStateIdle]; [gifFooter setImages:footerImages forState:MJRefreshStateRefreshing]; _tableView.footer = gifFooter; }
最后记得在数据加载完成时停掉loading
[_tableView.header endRefreshing];//下拉刷新数据完成时写上 [_tableView.footer endRefreshing];//上拉加载数据完成时写上