ios - Preload next (currently invisible) cell UICollectionView -


i'm working uicollectionview , have full screen cells , when swipe next cell image takes bit load cell (since they're high res). i'm using phcachingimagemanager cache image before hand , it's cached before load cell, loading image imageview takes noticeable spark of time. wondering if there's way preload invisible next cell before gets cellforitematindexpath?

any thoughts?

it apparently takes time load image has been cached phcachingimagemanager cause of delay. created test function saved next image (and add previous 1 too) in property while setting current cell , flicker no more. i'll post working example when i've cleaned up...

update: created _images nsmutabledictionary store loaded images , populate using function

- (void)startcachingsurroundingimages:(nsinteger)index { cgsize targetsize = phimagemanagermaximumsize; phimagerequestoptions *options = [[phimagerequestoptions alloc] init]; [options setnetworkaccessallowed:yes]; [options setdeliverymode:phimagerequestoptionsdeliverymodehighqualityformat];  if (index < _imagesarray.count - 1 && ![_images objectforkey:[nsindexpath indexpathforitem:0 insection:index+1]]) {     nsdictionary *assetdictionary = [_imagesarray objectatindex:index + 1];     nsstring *assetrefid = [assetdictionary objectforkey:@"asset_id"];      phfetchresult *assetfetchresult = [phasset fetchassetswithlocalidentifiers:@[assetrefid] options:[phfetchoptions new]];     phasset *asset = [assetfetchresult firstobject];        [photomanager requestimageforasset:asset targetsize:targetsize contentmode:phimagecontentmodeaspectfit options:options resulthandler:^(uiimage *result, nsdictionary *info) {         if (result) {             [_images setobject:result forkey:[nsindexpath indexpathforitem:0 insection:index+1]];         }     }]; }  if (index - 1 >= 0 && ![_images objectforkey:[nsindexpath indexpathforitem:0 insection:index-1]]) {     nsdictionary *leftassetdictionary = [_imagesarray objectatindex:index - 1];     nsstring *leftassetrefid = [leftassetdictionary objectforkey:@"asset_id"];      phfetchresult *leftassetfetchresult = [phasset fetchassetswithlocalidentifiers:@[leftassetrefid] options:[phfetchoptions new]];     phasset *leftasset = [leftassetfetchresult firstobject];      [photomanager requestimageforasset:leftasset targetsize:targetsize contentmode:phimagecontentmodeaspectfit options:options resulthandler:^(uiimage *result, nsdictionary *info) {         if (result) {             [_images setobject:result forkey:[nsindexpath indexpathforitem:0 insection:index-1]];         }     }];   } } 

which call in cellforitematindexpath so...

[self startcachingsurroundingimages:indexpath.section]; 

and still in cellforitematindexpath, load image so...

if ([_images objectforkey:indexpath]) {     cell.imageview.image = [_images objectforkey:indexpath];     [photocell.activityindicator sethidden:yes]; } else {     photocell.tag = (int)[photomanager requestimageforasset:asset targetsize:targetsize contentmode:phimagecontentmodeaspectfit options:options resulthandler:^(uiimage *result, nsdictionary *info) {         photocell *photocell = (photocell *)[self.collectionview cellforitematindexpath:indexpath];         if (photocell && result) {             photocell.imageview.image = result;             [photocell.activityindicator sethidden:yes];         } else {             nslog(@"bad image!!! %@", info);             [photocell.activityindicator sethidden:no];         }     }]; } 

then in didreceivememorywarning clean bit...

- (void)didreceivememorywarning {   nsarray *allkeys = [_images allkeys];   (int = 0; < _images.count; i++) {     nsindexpath *path = [allkeys objectatindex:i];     if (path.section != _lastindex && path.section != _lastindex - 1 && path.section != _lastindex + 1) {         [_images removeobjectforkey:path];     }   }   // though 1    // [_images removeallobjects]; } 

it's not pretty, works.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -