Mjrefresh Custom Refresh animation effect in Android development _android

Source: Internet
Author: User
Tags prepare

"One" common usage

The most original usage, the coupling degree is low, but cannot unify the management. We need to write the following code in each controller, very cumbersome, after the project to modify more cumbersome, a controller to a controller to locate, modify.

1.1 Use default refresh (coupling degree bottom, but want to unify change up special trouble)

Self.tableView.mj_header = [Mjrefreshnormalheader headerwithrefreshingblock:^{
//Perform refresh operations here
}];
Self.tableView.mj_header = [Mjrefreshnormalheader headerwithrefreshingtarget:self refreshingaction: @selector (Refresh method) ];

1.2 Custom Refresh (coupling degree bottom, but want to unify to change up special trouble)

1.2.1 Create a new custom refresh Mjrefreshnormalheader *customref =[mjrefreshnormalheader headerwithrefreshingblock:^{//
1.2.2 here to perform a refresh operation}];
1.2.3 Custom Refresh status text [Customref settitle:@ "Ordinary idle State" forstate:mjrefreshstateidle];
[Customref settitle:@ "release can be refreshed state" forstate:mjrefreshstatepulling];
[Customref settitle:@ "state in the Refresh" forstate:mjrefreshstaterefreshing];
[Customref settitle:@ "The state of the impending refresh" Forstate:mjrefreshstatewillrefresh];
[Customref settitle:@ "All data loading complete, no more data" forstate:mjrefreshstatenomoredata];
1.2.4 Add drop-down Refresh Self.tableView.mj_header = Customref;
Some other properties set///Set Font customRef.stateLabel.font = [Uifont systemfontofsize:15];
CustomRef.lastUpdatedTimeLabel.font = [Uifont systemfontofsize:14];
Set the color CustomRef.stateLabel.textColor = [Uicolor Redcolor];
CustomRef.lastUpdatedTimeLabel.textColor = [Uicolor Bluecolor];
Hidden time CustomRef.lastUpdatedTimeLabel.hidden = YES;
Hidden state CustomRef.stateLabel.hidden = YES;
Set automatic toggle Transparency (automatically hidden under the navigation bar) Customref.automaticallychangealpha = YES; */

"Two" correct usage (all dropdown refresh controls for the Unified management project)

There are 6 kinds of refreshing objects (all with red at the end of the picture).

If we want to implement the default Drop-down refresh,

"2.1" Just create a new object,

Inherited from Mjrefreshnormalheader,

#import "MJRefreshNormalHeader.h"
@interface hsnormalheader:mjrefreshnormalheader
@end

"2.2" and then rewrite the method-(void) prepare, after rewriting, remember to implement [Super prepare],

#import "HSNormalHeader.h" @implementation hsnormalheader #pragma mark-the method that overrides the parent class-(void) prepare{[super Prepare];/all from
Define everything here [self settitle:@ "ordinary idle State" forstate:mjrefreshstateidle];
[Self settitle:@] the state "forstate:mjrefreshstatepulling" that can be refreshed;
[Self settitle:@ The state in the Refresh ' forstate:mjrefreshstaterefreshing];
[Self settitle:@ "the state of the impending refresh" Forstate:mjrefreshstatewillrefresh];
[Self settitle:@ "all data loaded, no more data" forstate:mjrefreshstatenomoredata];
Some other properties set///Set 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];
Hidden time Self.lastUpdatedTimeLabel.hidden = YES;
Hidden state Self.stateLabel.hidden = YES;
Set automatic toggle Transparency (automatically hidden under the navigation bar) Self.automaticallychangealpha = YES; 
////If you need to rearrange the child controls yourself-(void) placesubviews{[super placesubviews];//If you need to rearrange the child controls yourself, please set//arrow//Self.arrowView.center = } @end

We then implement the corresponding controller to refresh as long as this can be:

"2.3" introduces custom objects, such as Hsnormalheader (inherited from Mjrefreshnormalheader),

#import "HSNormalHeader.h"

"2.4" in the need to pull the refresh controller so that the implementation can be

Self.tableView.mj_header = [Hsnormalheader headerwithrefreshingblock:^{
//Refresh request
}];

Similarly, the corresponding pull drawing can only be inherited from Mjrefreshgifheader by a new object

#pragma mark-the method that overrides the parent class
-(void) prepare{
[Super prepare];
Set the normal state of the animated picture
nsmutablearray *idleimages = [Nsmutablearray array];
for (Nsuinteger i = 1; i<=60; i++) {
uiimage *image = [uiimage imagenamed:[nsstring stringwithformat:@] Dropdown_ani M__000%zd ", I]];
[Idleimages addobject:image];
}
[Self setimages:idleimages forstate:mjrefreshstateidle];
Sets the animated picture of the state to be refreshed (a state that will refresh as soon as it is released)
nsmutablearray *refreshingimages = [Nsmutablearray array];
for (Nsuinteger i = 1; i<=3; i++) {
uiimage *image = [uiimage imagenamed:[nsstring stringwithformat:@] Dropdown_loa Ding_0%zd ", I]];
[Refreshingimages addobject:image];
}
[Self setimages:refreshingimages forstate:mjrefreshstatepulling];
Sets the animated picture in which the state is being refreshed
[self setimages:refreshingimages forstate:mjrefreshstaterefreshing];
Hidden time
Self.lastUpdatedTimeLabel.hidden = YES;
Hidden state
Self.stateLabel.hidden = YES;
}

At this point, you can say that the main functions of Mjrefresh have been mastered by you, if you need to master more please refer to MJ's address

Https://github.com/CoderMJLee/MJRefresh

The demo address of this case is HTTPS://GITHUB.COM/WOLFHOUS/HSUPDATEAPP

Note: Inside also contains an automatic detection update, we feel good please asterisking Oh!

The above is a small set to introduce the Android development Mjrefresh custom Refresh animation effect, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.