objective c - Custom animation when switching from one UICollectionViewLayout to another? -
as test made 1 layout displays cells in vertical line , displays them in horizontal layout. when phone call [collectionview setcollectionviewlayout:layout animated:yes];
animates between 2 positions cleanly.
now i'd like have views few spins, warps , flips around screen (probably using cakeyframeanimations) before arriving @ destination, can't find place hook in.
i tried subclassing uicollectionviewlayoutattributes
contain animation property, setting animations in overridden applylayoutattributes:
method of uicollectionviewcell
i'm using. works... except appears happen after layout transition complete. if wanted utilize this, i'd have have layout not alter current positions of objects right away, after reaches apply attributes part of code, , seems lot of work...
or subclass uicollectionview
, override setcollectionviewlayout:animated:
, seems lot of state maintain around between layouts. neither of these optins seems right, because there's such easy way animate additions/deletions of cells within layout. sense there should similar hooking animations between layouts.
does know best way i'm looking accomplish?
#define degreestoradians(x) (m_pi * (x) / 180.0) uicollectionview *collectionview = self.viewcontroller.collectionview; horizontalcollectionviewlayout *horizontallayout = [horizontalcollectionviewlayout new]; nstimeinterval duration = 2; [collectionview.visiblecells enumerateobjectsusingblock:^(uicollectionviewcell *cell, nsuinteger index, bool *stop) { cabasicanimation *rotationanimation; rotationanimation = [cabasicanimation animationwithkeypath:@"transform.rotation"]; rotationanimation.tovalue = @(degreestoradians(360)); rotationanimation.duration = duration; rotationanimation.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; [cell.layer addanimation:rotationanimation forkey:@"rotationanimation"]; }]; [uiview animatewithduration:duration animations:^ { collectionview.collectionviewlayout = horizontallayout; }];
objective-c ios6 uicollectionview uicollectionviewlayout
No comments:
Post a Comment