Monday, 15 April 2013

ios - UICollectionViewFlowLayout subclass causes cell to disappear -



ios - UICollectionViewFlowLayout subclass causes cell to disappear -

i trying offset center on y axis, of cells below selected cell. added property collectionviewflowlayout subclass, called extendedcell, marks cell below should offset else.

- (nsarray *)layoutattributesforelementsinrect:(cgrect)rect { nsarray *attributes = [super layoutattributesforelementsinrect:rect]; if(!self.extendedcell) { homecoming attributes; } else { homecoming [self offsetcells:attributes]; } } - (uicollectionviewlayoutattributes *)layoutattributesforitematindexpath:(nsindexpath *)indexpath { uicollectionviewlayoutattributes *attribute = [super layoutattributesforitematindexpath:indexpath]; if(!self.extendedcell) { homecoming attribute; } else { if(![attribute.indexpath isequal:self.extendedcell] && attribute.center.y >= [super layoutattributesforitematindexpath:self.extendedcell].center.y) { cgpoint newcenter = cgpointmake(attribute.center.x, attribute.center.y + 180.f); attribute.center = newcenter; } homecoming attribute; } } -(nsarray *)offsetcells:(nsarray *)layoutattributes { for(uicollectionviewlayoutattributes *attribute in layoutattributes) { if(![attribute.indexpath isequal:self.extendedcell] && attribute.center.y >= [super layoutattributesforitematindexpath:self.extendedcell].center.y) { cgpoint newcenter = cgpointmake(attribute.center.x, attribute.center.y + 180.0f); attribute.center = newcenter; } } homecoming layoutattributes; }

turns out bad happens on way, cells @ bottom disappear. have feeling has cells beingness outside uicollectionview content size, setting size while generating layout not help. ideas how prepare disappearance?

ok turns out found bug. seems overriding -(cgsize)collectionviewcontentsize helps. if cells lie outside content size of collection view disappear. content size set before layout attributes calls, , cells not allowed placed outside of it, collection view gets rid of them. thought content size based upon cells attributes after they've been set, not case.

-(cgsize)collectionviewcontentsize { if(self.extendedcell) { cgsize size = [super collectionviewcontentsize]; homecoming cgsizemake(size.width, size.height + 180); } else { homecoming [super collectionviewcontentsize]; } }

ios uicollectionview uicollectionviewcell uicollectionviewlayout

No comments:

Post a Comment