Mjrefresh GitHub Address: Https://github.com/CoderMJLee/MJRefresh
Using my spare time to study the development of iOS, I found that OC-specific grammar attracted me, and there was a lot of interesting things in iOS development, and it was the same that inspired my interest in development learning. In the process of self-study, I know that this mjrefresh,mj is a great God.
Needless to say, Mjrefresh integrated the Uiview,uicollectionview,uitableview refresh function, but also have custom text, animation and other functions. For GitHub on the source code to study a turn, to copy it again, understand the mechanism and look forward to learn from their own practical things new. I believe that after the knock over it is a new level of understanding.
The structure of the Mjrefresh is roughly the same:
Mjrefreshcomponent is naturally the parent class, which defines basic operations and properties such as basic text size, color, refresh events, block, and start refresh, end refresh, and so on.
1 @interfaceMjrefreshcomponent:uiview2 {3 uiedgeinsets _scrollvieworiginalinset;4__weak Uiscrollview *_scrollview;5 }6 7 #pragmaMark-word processing8 /** Text color*/9@property (Strong, nonatomic) Uicolor *TextColor;Ten /** Font Size*/ One@property (Strong, nonatomic) Uifont *font; A - #pragmaMark-Refresh Processing - /** Callback that is being refreshed*/ the@property (copy, nonatomic)void(^Refreshingblock) (); - /** Set Callback object and callback method*/ -- (void) Setrefreshingtarget: (ID) Target refreshingaction: (SEL) action; -@property (weak, nonatomic)IDRefreshingtarget; + @property (Assign, nonatomic) SEL refreshingaction; - /** Enter Refresh status*/ +- (void) beginrefreshing; A /** End Refresh Status*/ at- (void) endrefreshing; - /** Whether it is refreshing*/ --(BOOL) isrefreshing; - @end
I personally think that the two most important classes are Mjrefreshheader and Mjrefreshfooter. Because the essence of the refresh event is within these two classes, footer does not introduce much. I personally understand that, mainly through the KVO monitoring Contentoffset property changes to determine whether it is refreshing, or pull down, or is refreshing or change the state of refresh, core code of course, I still because of their own level of reason did not read too much, I believe that after knocking over will understand it. The core code is as follows:
#pragmaMark adjusts the state-according to Contentoffset (void) adjuststatewithcontentoffset{if(Self.state! =mjrefreshheaderstaterefreshing) { //During the refresh process, when you jump to the next controller, the Contentinset may change_scrollvieworiginalinset =_scrollview.contentinset; } //in the refreshed refreshing state, dynamically set the content inset if(Self.state = =mjrefreshheaderstaterefreshing) { if(_scrollview.contentoffset.y >=-_scrollvieworiginalinset.top) {_scrollview.mj_insett=_scrollvieworiginalinset.top; } Else{_scrollview.mj_insett= MIN (_scrollvieworiginalinset.top +Self.mj_h, _scrollvieworiginalinset.top-_scrollview.contentoffset.y); } return; } //the current ContentoffsetCGFloat OffsetY =_scrollview.mj_offsety; //offsety The head control just appearsCGFloat happenoffsety =-_scrollvieworiginalinset.top; //If you are scrolling up to the invisible Head control, return directly if(OffsetY >= happenoffsety)return; //the tipping point for normal and impending refreshesCGFloat normal2pullingoffsety = happenoffsety-Self.mj_h; if(_scrollview.isdragging) {self.pullingpercent= (happenoffsety-offsety)/Self.mj_h; if(Self.state = = Mjrefreshheaderstateidle && OffsetY <normal2pullingoffsety) { //transition to the state of impending refreshSelf.state =mjrefreshheaderstatepulling; } Else if(Self.state = = mjrefreshheaderstatepulling && OffsetY >=normal2pullingoffsety) { //transition to normal stateSelf.state =Mjrefreshheaderstateidle; } } Else if(self.state = = mjrefreshheaderstatepulling) {//about to refresh && hand releaseSelf.pullingpercent =1.0; //Start RefreshSelf.state =mjrefreshheaderstaterefreshing; } Else{self.pullingpercent= (happenoffsety-offsety)/Self.mj_h; }}
Finally, the Uiscrollview+mjrefresh extension is implemented to implement the Uiscrollview control drop-down refresh integration. Every time you read the code, there is a new harvest. Wait for what, go and knock it out.
On the understanding of the Mjrefresh (top) dropdown refresh Control