SoFunction
Updated on 2025-04-08

iOS uses MJRefresh to achieve custom refresh animation effects

This article mainly introduces iOS using MJRefresh to realize the pull-up refresh drop-down loading effect of custom animations. The general types (including update time and loading pattern) will not be introduced here.

To implement this function, you must first have a load image array.

Next is the implementation process:

Introduce header files:

#import ""
//Customize a method implementation- (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:^{
//Put down to refresh the operation to do. }];
  = YES;
  = 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:^{
//The operations required to be done for pulling up and loading. }];
  = YES;
  = YES;
 [gifFooter setImages:@[footerImages[0]]forState:MJRefreshStateIdle];
 [gifFooter setImages:footerImages forState:MJRefreshStateRefreshing];
 _tableView.footer = gifFooter;
}

Finally, remember to stop loading when the data is loaded

  [_tableView.header endRefreshing];//Write on when the pull-down refresh data is completed  [_tableView.footer endRefreshing];//Write on when the data is loaded up

The above is what the editor introduced to you about iOS using MJRefresh to achieve custom refresh animation effects. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!