i'm encountering same problem here large uicollectionviewcell (more twice of uicollectionview height apparently) disappear @ given scrolling offset , reappear after given scrolling offset also.
i've implemented @jonathancichon solution subclass uicollectionview , perform custom action on _visiblebounds
(i know it's private api no matter, don't need submit on apple store)
here custom collection view :
#import "collectionview.h" @interface uicollectionview () - (cgrect)_visiblebounds; @end @implementation collectionview - (cgrect)_visiblebounds { cgrect rect = [super _visiblebounds]; rect.size.height = [self heightoflargestvisiblecell]; return rect; } - (cgfloat)heightoflargestvisiblecell { // current screen height depending on orientation cgfloat screensize = [self currentscreenheight]; cgfloat largestcell = 0; nsarray *visiblecells = self.visiblecells; // largest height between visiblecells (uitableviewcell *c in visiblecells) { cgfloat h = c.frame.size.height; largestcell = h > largestcell ? h : largestcell; } // return higher value between screen height , higher visible cell height return max(largestcell, screensize); }
this works, no more disappeared on scrolling still have problem : if perform reloaddata
when scroll position in middle of large cell, disappear earlier ... i've noticed after reloading data, visiblecells
return nil
(in heightoflargestvisiblecell
method), take screen height _visiblebounds
since screen height < current visible cell height, 1 not displayed ...
someone faced issue ?
thx in advance
i got solution problem. store value calculated heightoflargestvisiblecell , return last value after reload data.
@interface collectionview : uicollectionview @property (nonatomic, assign) cgfloat lastlargestcellheight; @property (nonatomic, assign) bool shouldevallargestcellheight; @end @implementation collectionview - (cgrect)_visiblebounds { cgrect rect = [super _visiblebounds]; rect.size.height = [self heightoflargestvisiblecell]; return rect; } - (cgfloat)heightoflargestvisiblecell { if (self.shouldevallargestcellheight) { // current screen height depending on orientation cgfloat screensize = self.frame.size.height; cgfloat largestcell = 0; nsarray *visiblecells = self.visiblecells; // largest height between visiblecells (uitableviewcell *c in visiblecells) { cgfloat h = c.frame.size.height; largestcell = h > largestcell ? h : largestcell; } //return higher value between screen height , higher visible cell height self.lastlargestcellheight = max(largestcell, screensize); self.shouldevallargestcellheight = no; } return self.lastlargestcellheight; } - (void)reloaddata { self.shouldevallargestcellheight = no; [super reloaddata]; } - (void)setcontentoffset:(cgpoint)contentoffset { self.shouldevallargestcellheight = yes; [super setcontentoffset:contentoffset]; } @end
Comments
Post a Comment