ios - UiCollectionViewCell random images flipping -
i have been looking around here answer no success ill make try self.
im trying make uicollectionview different cells containing images + animation cells.
i want cells "random flipping" images (5 different images)
uiviewanimationoptiontransitionflipfromleft
in loop 5-6 sec delay.
the animation have moment this:
- (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *cell = [collectionview cellforitematindexpath:indexpath]; [cell.superview bringsubviewtofront:collectionview]; [uiview transitionwithview:cell duration:1.0 options:uiviewanimationoptiontransitionflipfromleft animations:^{ [uicollectionviewcell commitanimations]; cell.transform = cgaffinetransformmakerotation(0.0); } completion:^(bool finished) {}]; }
i know shouldn't use didselectitematindexpath, used see if animation right.
if check @ video u can see mean, on windows 8 phone. youtube video
ok, interested on idea prototyped code. needs tailored needs can start. firstly, need subclass uicollectionviewcell
in order connect iboutlet
imageview inside cell. can reference code snippet started.
- (void)viewdidload { [super viewdidload]; self.imagelist = @[@"img1.png", @"img2.png", @"img3.png", @"img4.png"]; } // assumes images inside bundle. - (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; [nstimer scheduledtimerwithtimeinterval:4.0 target:self selector:@selector(updatecells:) userinfo:nil repeats:yes]; } - (void)updatecells:(nstimer *)timer { nsarray *visibleindexpaths = [self.collectionview indexpathsforvisibleitems]; (nsindexpath *indexpath in visibleindexpaths) { subclasscollectionviewcell *cell = (subclasscollectionviewcell *)[self.collectionview cellforitematindexpath:indexpath]; [uiview transitionwithview:cell duration:1.0f options:uiviewanimationoptiontransitionflipfromleft animations:^{ cell.imageview.image = [self randomimage]; } completion:nil]; } } - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return 1; } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"cell" forindexpath:indexpath]; return cell; } - (uiimage *)randomimage { nsinteger randomnumber = arc4random() % [self.imagelist count]; return [uiimage imagenamed:[self.imagelist objectatindex:randomnumber]]; }
update:
if want 1 cell @ time randomly flip, need take out for
loop in updatecells
method. instead, try this:
- (void)updatecells:(nstimer *)timer { nsarray *visibleindexpaths = [self.collectionview indexpathsforvisibleitems]; nsinteger randomindex = arc4random() % [visibleindexpaths count]; nsindexpath *randomindexpath = [nsindexpath indexpathforitem:randomindex insection:0]; subclasscollectionviewcell *cell = (subclasscollectionviewcell *)[self.collectionview cellforitematindexpath:indexpath]; [uiview transitionwithview:cell duration:1.0f options:uiviewanimationoptiontransitionflipfromleft animations:^{ cell.imageview.image = [self randomimage]; } completion:nil ]; }
Comments
Post a Comment