MJRefresh custom refresh animation,

Source: Internet
Author: User

MJRefresh custom refresh animation,
[1] most common usage: low coupling, but not unified management. We need to write the following code in every controller, which is complicated. In the future, project modification will be more complicated. We need to locate and modify a controller.

1.1 use the default refresh (the coupling degree is low, but it is especially troublesome to modify it in a unified manner)

Self. tableView. mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock: ^ {// execute the refresh operation here}]; self. tableView. mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget: self refreshingAction: @ selector (refresh method)];

1.2 custom refresh (low coupling degree, but it is especially troublesome to modify it in a unified manner)

// 1.2.1 create a custom refresh MJRefreshNormalHeader * customRef = [MJRefreshNormalHeader headerWithRefreshingBlock: ^ {// 1.2.2 execute the refresh operation here}]; // 1.2.3 custom refresh status text [customRef setTitle: @ "normal idle status" forState: MJRefreshStateIdle]; [customRef setTitle: @ "" forState: MJRefreshStatePulling]; [customRef setTitle: @ "status in refresh" forState: Refreshing]; [customRef setTitle: @ "status to be refreshed" forState: MJRefreshStateWillRefresh]; [customRef setTitle: @ "all data is loaded and no more data is available" forState: MJRefreshStateNoMoreData]; // 1.2.4 Add a drop-down refresh self. tableView. mj_header = customRef; // set some other attributes/* // set the font customRef. stateLabel. font = [UIFont systemFontOfSize: 15]; customRef. lastUpdatedTimeLabel. font = [UIFont systemFontOfSize: 14]; // set the customRef color. stateLabel. textColor = [UIColor redColor]; customRef. lastUpdatedTimeLabel. textColor = [UIColor blueColor]; // hide customRef. lastUpdatedTimeLabel. hidden = YES; // customRef in the hidden state. stateLabel. hidden = YES; // sets the automatic switch transparency (automatically hidden under the navigation bar) customRef. automaticallyChangeAlpha = YES ;*/
[2] correct usage (unified management of all drop-down and refresh controls of the project)

There are 6 types of refresh objects (red at the end of the image ).

If we want to implement the default pull-down refresh,
[2.1] As long as a new object is created,
Inherited fromMJRefreshNormalHeader,

#import "MJRefreshNormalHeader.h"@interface HSNormalHeader : MJRefreshNormalHeader@end

[2.2] Then rewrite the Method- (void)prepareAfter rewriting, remember to implement[super prepare],

# Import "HSNormalHeader. h "@ implementation HSNormalHeader # pragma mark-override the parent class method-(void) prepare {[super prepare]; // all custom definitions are placed here [self setTitle: @ "normal idle state" forState: MJRefreshStateIdle]; [self setTitle: @ "the refresh state can be released" forState: MJRefreshStatePulling]; [self setTitle: @ "status in refresh" forState: MJRefreshStateRefreshing]; [self setTitle: @ "status to be refreshed" forState: MJRefreshStateWillRefresh]; [self setTitle: @ "all data has been loaded, no more data. "forState: MJRefreshStateNoMoreData]; // set some other attributes. // set the font self. stateLabel. font = [UIFont systemFontOfSize: 15]; self. lastUpdatedTimeLabel. font = [UIFont systemFontOfSize: 14]; // set the color self. stateLabel. textColor = [UIColor redColor]; self. lastUpdatedTimeLabel. textColor = [UIColor blueColor]; // hide time self. lastUpdatedTimeLabel. hidden = YES; // hide the status self. stateLabel. hidden = YES; // sets the automatic switch transparency (automatically hidden under the navigation bar) self. automaticallyChangeAlpha = YES; * // if you need to re-layout the sub-control-(void) placeSubviews {[super placeSubviews]; // if you need to re-layout the sub-control, set // arrow // self. arrowView. center =}@ end

Then we can refresh the corresponding controller as long as it can:
[2.3] introduce a custom object, suchHSNormalHeader(Inherited fromMJRefreshNormalHeader),

#import "HSNormalHeader.h"

[2.4] the Controller that needs to be pulled down and refreshed can be implemented in this way

Self. tableView. mj_header = [HSNormalHeader headerWithRefreshingBlock: ^ {// refresh request}];

Similarly, the corresponding drop-down animation only needs to create a new object that inherits fromMJRefreshGifHeader

# Pragma mark-override the parent class method-(void) prepare {[super prepare]; // set the normal state animation image 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]; // sets the animation image to be refreshed when it is released) 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]; // set the animation image in the refreshing State [self setImages: refreshingImages forState: MJRefreshStateRefreshing]; // hide the time self. lastUpdatedTimeLabel. hidden = YES; // hide the status self. stateLabel. hidden = YES ;}

So far, it can be said that the common main functions of MJRefresh have been completed by you, if you need to master more please refer to MJ's address https://github.com/CoderMJLee/MJRefresh

The demo address in this case is workshop!

 

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.