iphone - UICollectionViewCell add animation for selected/highlighted item -


i'm implementing simple collection view images inside cells. task want achieve when user taps on cell - there should flip animation , details have appear @ same cell.

i've tried lot of things achieve that, example i've added 2 views on contentview of cell. , when user pushes button called transitiontoview method , worked fine, except when list contained more 9-10 images, after scrolling list cells started duplicate "flipped" view no reason. turned off dequeuereusablecellwithreuseidentifier function , worked fine, on older devices iphone4, application worked slowly.

so best solution found this:

- (uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath; {      uicollectionviewcell *cell1 = [cv dequeuereusablecellwithreuseidentifier:kcellid3 forindexpath:indexpath];enter code here      uiview *contents = [[uiview alloc]initwithframe:cell1.bounds];     contents.layer.bordercolor = [[uicolor colorwithred:0.119 green:0.108 blue:0.222 alpha:1]cgcolor];     contents.layer.borderwidth = 10.0f;     contents.backgroundcolor = [uicolor yellowcolor];     [cell1.contentview addsubview:contents];      uiview *backgroundview = [[uiview alloc]initwithframe:cell1.bounds];     backgroundview.layer.bordercolor = [[uicolor colorwithred:0.529 green:0.808 blue:0.922 alpha:1]cgcolor];     backgroundview.layer.borderwidth = 4.0f;     backgroundview.backgroundcolor = [uicolor greencolor];     cell1.selectedbackgroundview = backgroundview;     [cell1 bringsubviewtofront:cell1.selectedbackgroundview];      return cell1; } 

but possible add animation event when cell becomes selected?

- (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath {     uicollectionviewcell *cell1 = [collectionview cellforitematindexpath:indexpath];      uiview *toswitch = cell1.contentview;     [uiview transitionfromview:toswitch toview:cell1.selectedbackgroundview duration:0.33 options:uiviewanimationoptioncurvelinear |uiviewanimationoptiontransitionflipfromleft completion:nil];  } 

also attempt ruins cells - when 1 or more of cells flipped other start copy it..

so need animation (what achieved), need keep other uicollectionview cells unique , don't reuse flipped view..

please help! :) desperate this!

thanks in advance

some solution:

- (void)collectionview:(uicollectionview *)collectionview didenddisplayingcell:(uicollectionviewcell *)cell foritematindexpath:(nsindexpath *)indexpath {     if(cell.selected)     {         [cell setselected:no];         [collectionview deselectitematindexpath:indexpath animated:no];         uiview *toswitch = cell.contentview;         [uiview transitionfromview:cell.selectedbackgroundview toview:toswitch duration:0.001 options:uiviewanimationoptioncurvelinear |uiviewanimationoptiontransitionflipfromleft completion:nil];     } } 

pretty temporary solution.. has better advice?

when scroll, "old cells" reused - that's makes table view perform well. of course, if cell in question has transitioned view, show 1 instead.

so, data in cell set anew in each call cellforitematindexpath function, have set right view visible - remember state of cell's view data, show according view when cell presented.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -