objective c - How can IOS Photos app can show hundreds of photos in one screen? -
objective c - How can IOS Photos app can show hundreds of photos in one screen? -
i working on application relies on showing lots of photos on screen multiple sources.
i wondering how apple create "photo tile" view in photo app? much photos, in sentiment app should give memory warning less photos (even if load photos in "thumbnail size") displayed @ once, can see can show hundreds of photos in 1 screen when zoom out.
one way can think of these views not individual photos single 'tiled' images generated photos on real time, app shows 2-3 photos @ once. still needs lots of cpu powerfulness , time generate fast. can zoom in or out instantly .
i want accomplish similar functionality in app, directions on how accomplish great.
thanks answers.
i have made research , found ios8 has wonderful new framework called "photos framework"
this framework lets cache images, phone call thumbnail images predefined sizes , load items. (old alasset library had 1 "thumbnail" size, had resize own.)
on test screen total of 20x20 photos (my phones screen content 384 images), app takes 10mb's of memory, , no flickering when scrolling. smooth scrolling can achieved optimizing cell reloading imo.
heres code i've used loading images uicollectionview 20x20 item size:
@import photos; @interface mainviewcontroller () @property (strong) phfetchresult *assetsfetchresults; @property (strong) phcachingimagemanager* imagemanager; @end
on viewdidload:
- (void)viewdidload { [super viewdidload]; self.imagemanager = [[phcachingimagemanager alloc] init]; cgfloat scale = [uiscreen mainscreen].scale; cgsize cellsize = ((uicollectionviewflowlayout *)self.collectionviewlayout).itemsize; assetgridthumbnailsize = cgsizemake(cellsize.width * scale, cellsize.height * scale); [self.collectionview registerclass:[uicollectionviewcell class] forcellwithreuseidentifier:reuseidentifier]; self.assetsfetchresults = [phasset fetchassetswithoptions:nil]; // additional setup after loading view. }
and collection view datasource methods:
#pragma mark <uicollectionviewdatasource> - (nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview { homecoming 1; } - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { homecoming self.assetsfetchresults.count; } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:reuseidentifier forindexpath:indexpath]; [self.imagemanager requestimageforasset:self.assetsfetchresults[indexpath.item] targetsize:cgsizemake(20, 20) contentmode:phimagecontentmodeaspectfill options:nil resulthandler:^(uiimage *result, nsdictionary* info){ uiimageview* imgview = (uiimageview*)[cell.contentview viewwithtag:999]; if(!imgview) { imgview = [[uiimageview alloc] initwithframe:[cell.contentview bounds]]; imgview.tag = 999; [cell.contentview addsubview:imgview]; } imgview.image = result; }]; // configure cell homecoming cell; }
thats it!
ios objective-c uicollectionview
Comments
Post a Comment