MJRefresh framework usage and description, mjrefresh framework Description

Source: Internet
Author: User

MJRefresh framework usage and description, mjrefresh framework Description

1. MJRefresh class explanation.

1. The base category of all MJRefreshComponent refresh controls. (component: component, component)

2. MJRefreshNormalHeader default drop-down refresh control

3. MJRefreshAutoNormalFooter's default pull-on refresh control pull-down refresh control adaptive under the page content

4. MJRefreshAutoGifFooter pull-on control with a dynamic graph pull-down refresh control adaptive below the page content

5. MJRefreshBackNormalFooter's default pull-on refresh control pull-down refresh control stays at the bottom of the screen

6. MJREfreshBackGifFooter's default pull-on animation refresh control pull-down refresh control stays at the bottom of the screen

 

Summary: refresh controls include headers and footer controls. headers and backend refresh controls.

The refresh controls are divided into normal and gif statuses. The normal and refresh controls and the refresh controls of gif dynamic graphs.

Tail refresh controls are divided into auto and back modes. Adaptive tail refresh controls and refresh controls are located at the bottom.

2. External methods provided in each class.

1. MJRefreshComponent

(1) beginRefreshing // start to refresh. It is called when you want to automatically refresh the page.

IsRefreshing // whether or not the refresh is being performed

EndRefreshing // end refresh, which is used when the network request ends.

(2) refresh the status of the MJRefreshState control.

/** Refresh control status */typedef NS_ENUM (NSInteger, MJRefreshState) {/** normal idle status */MJRefreshStateIdle = 1, /** refresh status after release */MJRefreshStatePulling,/** status in refresh */MJRefreshStateRefreshing,/** status to be refreshed */MJRefreshStateWillRefresh, /** after loading all the data, no more data is available */MJRefreshStateNoMoreData };

(3) automaticallyChangeAlpha automatically switches transparency based on the drag ratio

2. MJRefreshHeader

(1)

/** This key is used to store the last time the pull-down refresh was successful */@ property (copy, nonatomic) NSString * lastUpdatedTimeKey;
/** Last time when the pull-down refresh was successful */@ property (strong, nonatomic, readonly) NSDate * lastUpdatedTime;

(2)

/** Create header */+ (instancetype) headerWithRefreshingBlock :( partial) refreshingBlock;/** create header */+ (instancetype) headerWithRefreshingTarget :( id) target refreshingAction :( SEL) action;

3. MJRefreshFooter

(1)

/** Create footer */+ (instancetype) Configure :( break) refreshingBlock;/** create footer */+ (instancetype) footerWithRefreshingTarget :( id) target refreshingAction :( SEL) action;

(2) endRefreshingWithNoMoreData indicates that no more data exists.

ResetNoMoreData reset no more data

(3) automaticallyHidden automatically displays or hides data based on whether data exists. (If data exists, it is displayed. If NO data exists, it is hidden. The default value is NO)

Iii. Specific Use

1. Default refresh Method

Header refresh control: MJRefreshNormalHeader

Tail refresh control: MJRefreshAutoNormalFooter

-(UITableView *) tableView {if (! _ TableView) {self. tableView = [[UITableView alloc] initWithFrame: CGRectZero style: UITableViewStylePlain]; self. tableView. dataSource = self; self. tableView. delegate = self; // The default pull-down refresh and pull-up load self. tableView. mj_header = [MJRefreshNormalHeader failed: ^ {// processing dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (2 * NSEC_PER_SEC), forward (), ^ {[self. tableView. mj_header endRefreshing];}) ;}]; self. tableView. mj_footer = [dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (2 * NSEC_PER_SEC), bytes (), ^ {[self. tableView. mj_footer endRefreshing];}) ;}];} return _ tableView ;}

 

2. Display Animation

Header refresh control: MJRefreshGifHeader

Tail refresh control: MJRefreshAutoGifFooter/MJRefreshBackGifFooter

-(UITableView *) tableView {if (! _ TableView) {self. tableView = [[UITableView alloc] initWithFrame: CGRectZero style: UITableViewStylePlain]; self. tableView. dataSource = self; self. tableView. delegate = self; then * header = [MJRefreshGifHeader failed: ^ {dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (3 * NSEC_PER_SEC), failed (), ^ {[self. tableView. mj_header endRefreshing];}) ;}]; NSMutableArray * arrayM = [NSMutableArray arrayWithCapacity: 0]; for (int I = 0; I <30; I ++) {UIImage * image = [UIImage imageNamed: [NSString stringWithFormat: @ "xz_flower _ % d", I + 1]; [arrayM addObject: image];} // set an Animated Image in normal state --> a static image NSArray * normalImagesArray = @ [[UIImage imageNamed: @ "xz_flower_1"]; [header setImages: normalImagesArray forState: MJRefreshStateIdle]; // sets the animation image to be refreshed [header setImages: arrayM forState: MJRefreshStatePulling]; // sets the animation image in the refreshing State [header setImages: arrayM forState: MJRefreshStateRefreshing]; // sets the header self. tableView. mj_header = header;} return _ tableView ;}

 

3. Set the display or hide of the time and status of the refresh control.

-(UITableView *) tableView {if (! _ TableView) {self. tableView = [[UITableView alloc] initWithFrame: CGRectZero style: UITableViewStylePlain]; self. tableView. dataSource = self; self. tableView. delegate = self; then * header = [MJRefreshGifHeader failed: ^ {dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (3 * NSEC_PER_SEC), failed (), ^ {[self. tableView. mj_header endRefreshing];}) ;}]; NSMutableArray * arrayM = [NSMutableArray arrayWithCapacity: 0]; for (int I = 0; I <30; I ++) {UIImage * image = [UIImage imageNamed: [NSString stringWithFormat: @ "xz_flower _ % d", I + 1]; [arrayM addObject: image];} NSArray * normalImagesArray = @ [[UIImage imageNamed: @ "xz_flower_1"]; [header setImages: normalImagesArray forState: Unknown]; [header setImages: arrayM forState: Unknown]; [header setImages: arrayM forState: MJRefreshStateRefreshing]; // hide the time header. lastUpdatedTimeLabel. hidden = YES; // hide the status header. stateLabel. hidden = YES; // set header self. tableView. mj_header = header;} return _ tableView ;}

 

4. Customize the text size and color of the refresh control

-(UITableView *) tableView {if (! _ TableView) {self. tableView = [[UITableView alloc] initWithFrame: CGRectZero style: UITableViewStylePlain]; self. tableView. dataSource = self; self. tableView. delegate = self; then * header = [MJRefreshNormalHeader failed: ^ {dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (2 * NSEC_PER_SEC), failed (), ^ {[self. tableView. mj_header endRefreshing];}) ;}]; // set the text [header setTitle: @ "pull-down refresh" forState: MJRefreshStateIdle]; [header setTitle: @ "Update" forState: MJRefreshStatePulling]; [header setTitle: @ "Loading... "forState: MJRefreshStateRefreshing]; // set the font header. stateLabel. font = [UIFont systemFontOfSize: 15]; header. lastUpdatedTimeLabel. font = [UIFont systemFontOfSize: 12]; // sets the color header. stateLabel. textColor = [UIColor redColor]; header. lastUpdatedTimeLabel. textColor = [UIColor redColor]; [header beginRefreshing]; self. tableView. mj_header = header;} return _ tableView ;}

 

5. When all the data is loaded, change the display of the tail refresh control (refresh is not allowed)

- (UITableView *)tableView{    if (!_tableView)    {        self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];                self.tableView.dataSource = self;        self.tableView.delegate = self;                MJRefreshAutoNormalFooter * footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{                [self.tableView.mj_footer endRefreshing];                [self.tableView.mj_footer endRefreshingWithNoMoreData];            });        }];        self.tableView.mj_footer = footer;    }    return _tableView;}

 

Resetting loaded

    [self.tableView.mj_footer resetNoMoreData];

 

6. Custom refresh control

Inherit MJRefreshHeader/MJRefreshGifHeader/MJRefreshAutoGifFooter/MJRefreshBackGifFooter/MJRefreshAutoFooter/MJRefreshBackFooter

#import "MJRefreshHeader.h"@interface MCDIYHeader : MJRefreshHeader@end

 

# Import "MCDIYHeader. h "@ interface MCDIYHeader () @ property (weak, nonatomic) UILabel * label; @ property (weak, nonatomic) UISwitch * s; @ property (weak, nonatomic) UIImageView * logo; @ property (weak, nonatomic) UIActivityIndicatorView * loading; @ end @ implementation MCDIYHeader # pragma mark-Rewrite method # pragma mark initializes the configuration here (for example, adding a child Control) -(void) prepare {[super prepare]; // sets the height of the control self. mj_h = 50; // Add label UILabel * label = [[UILabel alloc] init]; label. textColor = [UIColor colorWithRed: 1.0 green: 0.5 blue: 0.0 alpha: 1.0]; label. font = [UIFont boldSystemFontOfSize: 16]; label. textAlignment = NSTextAlignmentCenter; [self addSubview: label]; self. label = label; // switch UISwitch * s = [UISwitch alloc] init]; [self addSubview: s]; self. s = s; // logo UIImageView * logo = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "Logo"]; logo. contentMode = UIViewContentModeScaleAspectFit; [self addSubview: logo]; self. logo = logo; // loading UIActivityIndicatorView * loading = [[UIActivityIndicatorView alloc] runtime: UIActivityIndicatorViewStyleGray]; [self addSubview: loading]; self. loading = loading ;}# pragma mark set the position and size of the Child control here-(void) placeSubviews {[super placeSubviews]; self. label. frame = self. bounds; self. logo. bounds = CGRectMake (0, 0, self. bounds. size. width, 100); self. logo. center = CGPointMake (self. mj_w * 0.5,-self. logo. mj_h + 20); self. loading. center = CGPointMake (self. mj_w-30, self. mj_h * 0.5) ;}# pragma mark listens to contentOffset change of scrollView-(void) scrollViewContentOffsetDidChange :( NSDictionary *) change {[super scrollViewContentOffsetDidChange: change];} # pragma mark listens to scrollView contentSize change-(void) scrollViewContentSizeDidChange :( NSDictionary *) change {[super resume: change] ;}# pragma mark listens to scrollView drag status change-(void) updated :( NSDictionary *) change {[super scrollViewPanStateDidChange: change];} # refresh status of The pragma mark monitoring control-(void) setState :( MJRefreshState) state {MJRefreshCheckState; switch (state) {case MJRefreshStateIdle: [self. loading stopAnimating]; [self. s setOn: NO animated: YES]; self. label. text = @ "hurry up and drop down (the switch is soy sauce drop)"; break; case MJRefreshStatePulling: [self. loading stopAnimating]; [self. s setOn: YES animated: YES]; self. label. text = @ "Let Me Go (the switch is soy sauce drop)"; break; case MJRefreshStateRefreshing: [self. s setOn: YES animated: YES]; self. label. text = @ "loading data (the switch is soy sauce drop)"; [self. loading startAnimating]; break; default: break ;}# pragma mark listens to the drag-and-drop ratio (proportion of the control dragged out)-(void) setPullingPercent :( CGFloat) pullingPercent {[super setPullingPercent: pullingPercent]; // 1.0 0.5 0.0 0.5 // 0.0 0.5 CGFloat red = 1.0-pullingPercent * 0.5; CGFloat green = 0.5-0.5 * pullingPercent; CGFloat blue = 0.5 * pullingPercent; self. label. textColor = [UIColor colorWithRed: red green: green blue: blue alpha: 1.0] ;}@ end

 

Usage:

-(UITableView *) tableView {if (! _ TableView) {self. tableView = [[UITableView alloc] initWithFrame: CGRectZero style: UITableViewStylePlain]; self. tableView. dataSource = self; self. tableView. delegate = self; // use the custom refresh control self. tableView. mj_header = [MCDIYHeader headerWithRefreshingBlock: ^ {dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (2 * NSEC_PER_SEC), callback (), ^ {[self. tableView. mj_header endRefreshing] ;}); [self. tableView. mj_header beginRefreshing];} return _ tableView ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.