Uicollectionview's header hover

Source: Internet
Author: User

Uicollectionview header hover, inherit Uicollectionviewflowlayout, override related methods

////StickyHeaderLayout.h//Wombat////Created by Todd Laney on 1/9/13.//Copyright (c) toddla. All rights reserved.////Modified fromhttp://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-usingthanks!// #import<UIKit/UIKit.h>@interfaceStickyheaderlayout:uicollectionviewflowlayout@end

////STICKYHEADERFLOWLAYOUT.M//Wombat////Created by Todd Laney on 1/9/13.//Copyright (c) toddla. All rights reserved.////Modified fromhttp://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-usingthanks!// #import "StickyHeaderFlowLayout.h" @implementationStickyheaderflowlayout-(Nsarray *) Layoutattributesforelementsinrect: (cgrect) rect {nsmutablearray*answer =[[Super Layoutattributesforelementsinrect:rect] mutablecopy]; Nsmutableindexset*missingsections =[Nsmutableindexset Indexset];  for(Nsuinteger idx=0; Idx<[answer Count]; idx++) {uicollectionviewlayoutattributes*layoutattributes =Answer[idx]; if(Layoutattributes.representedelementcategory = =Uicollectionelementcategorycell)  {[Missingsections addIndex:layoutAttributes.indexPath.section]; //Remember that we need to layout header for this section        }        if([Layoutattributes.representedelementkind Isequaltostring:uicollectionelementkindsectionheader]) {[Answer  REMOVEOBJECTATINDEX:IDX]; //Remove layout of header done by our super, we 'll do it right lateridx--; }    }        //layout All headers needed-the RECT using self code[Missingsections enumerateindexesusingblock:^ (Nsuinteger idx, BOOL *stop) {Nsindexpath*indexpath = [Nsindexpath indexpathforitem:0Insection:idx]; Uicollectionviewlayoutattributes*layoutattributes =[self Layoutattributesforsupplementaryviewofkind:uicollectionelementkindsectionheader atIndexPath:indexPath]        ;    [Answer addobject:layoutattributes];        }]; returnanswer;} -(Uicollectionviewlayoutattributes *) Layoutattributesforsupplementaryviewofkind: (NSString *) kind AtIndexPath: ( Nsindexpath *) Indexpath {uicollectionviewlayoutattributes*attributes =[Super Layoutattributesforsupplementaryviewofkind:kind Atindexpath:indexpath]; if([Kind Isequaltostring:uicollectionelementkindsectionheader]) {Uicollectionview*ConstCV =Self.collectionview; CgpointConstContentoffset =Cv.contentoffset; Cgpoint Nextheaderorigin=Cgpointmake (INFINITY, INFINITY); if(indexpath.section+1<[CV numberofsections]) {Uicollectionviewlayoutattributes*nextheaderattributes = [Super Layoutattributesforsupplementaryviewofkind:kind Atindexpath:[nsindexpath Indexpathforitem:0insection:indexpath.section+1]]; Nextheaderorigin=NextHeaderAttributes.frame.origin; } CGRect Frame=Attributes.frame; if(Self.scrolldirection = =uicollectionviewscrolldirectionvertical) {FRAME.ORIGIN.Y= MIN (MAX (Contentoffset.y, FRAME.ORIGIN.Y), NEXTHEADERORIGIN.Y-Cgrectgetheight (frame)); }        Else{//Uicollectionviewscrolldirectionhorizontalframe.origin.x = MIN (MAX (Contentoffset.x, frame.origin.x), nextheaderorigin.x-Cgrectgetwidth (frame)); } Attributes.zindex=1024x768; Attributes.frame=frame; }    returnattributes;} -(Uicollectionviewlayoutattributes *) Initiallayoutattributesforappearingsupplementaryelementofkind: (NSString *) Kind Atindexpath: (Nsindexpath *) Indexpath {uicollectionviewlayoutattributes*attributes =[self layoutattributesforsupplementaryviewofkind:kind atindexpath:indexpath]; returnattributes;}-(Uicollectionviewlayoutattributes *) Finallayoutattributesfordisappearingsupplementaryelementofkind: (NSString *) Kind Atindexpath: (Nsindexpath *) Indexpath {uicollectionviewlayoutattributes*attributes =[self layoutattributesforsupplementaryviewofkind:kind atindexpath:indexpath]; returnattributes;} -(BOOL) Shouldinvalidatelayoutforboundschange: (CGRect) Newbound {returnYES;} @end

Source: https://gist.github.com/evadne/4544569

Uicollectionview's header hover

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.