iphone - Cannot set animation duration -
good day, everyone!
well, i've got simple trouble. i've got catransformlayer 2 sublayers, each "false" doublesided property, , forms double-sided card. problem is, cannot set animation duration or other options, like, example, uiviewanimationcurveeaseinout etc. tried new , old 1 method add animation options , duration layer, but, unfortunately, rotates 0,25 seconds, default value states. what's wrong? suggestions appreciated.
here 's code :
1) initialization of stuff :
#ifndef supported_macro #define degrees_to_radians(angle) (angle * m_pi / 180.0) #endif - (void)viewdidload { [super viewdidload]; [super viewdidload]; catransformlayer *cardcontainer = [catransformlayer layer]; cardcontainer.anchorpoint = cgpointmake( 0.5 , 1.0 ) ; cardcontainer.position = cgpointmake(100.0, 200.0) ; cardcontainer.bounds = cgrectmake(0.0, 0.0, 150.0, 170.0); calayer *cardfront = [calayer layer]; // front part of card cardfront.bounds = cgrectmake(0.0, 0.0, cardcontainer.bounds.size.width, cardcontainer.bounds.size.height) ; cardfront.frame = cardcontainer.bounds ; cardfront.contentsgravity = kcagravityresizeaspect ; cardfront.bordercolor = [uicolor blackcolor].cgcolor; cardfront.borderwidth = 2.0; cardfront.cornerradius = 30.0; [cardcontainer addsublayer:cardfront]; calayer *cardback = [calayer layer]; //back part of card cardback.bounds = cgrectmake(0.0, 0.0, cardcontainer.bounds.size.width, cardcontainer.bounds.size.height) ; cardback.frame = cardcontainer.bounds; cardback.contentsgravity = kcagravityresizeaspect ; cardback.bordercolor = [uicolor blackcolor].cgcolor; cardback.borderwidth = 2.0; cardback.cornerradius = 30.0; cardback.doublesided = no; cardback.transform = catransform3dmakerotation(degrees_to_radians(180.0),0.0,1.0,0.0); [cardcontainer addsublayer:cardback]; ((calayer*)[cardcontainer.sublayers objectatindex:0]).contents = (id)[uiimage imagenamed:@"1.png"].cgimage ; ((calayer*)[cardcontainer.sublayers objectatindex:1]).contents = (id)[uiimage imagenamed:@"2.png"].cgimage ; tl = cardcontainer ; [self.view.layer addsublayer:cardcontainer]; }
2) procedure rotate ( in deprecated style) :
-(void)rotate { static double callcounter = 1.0 ; auto catransform3d t3d = catransform3didentity; t3d.m34 = 1.0/-500.0; [uiview beginanimations:nil context:null]; [uiview setanimationcurve:uiviewanimationcurveeaseinout]; [uiview setanimationduration:1.75]; tl.sublayertransform = catransform3drotate(t3d, -(callcounter*m_pi) , 1.0, 0.0, 0.0) ; [uiview commitanimations]; callcounter += 1.0 ; }
well, problem simple. thing is, not every property of object can animated. example, can't animate expression :
int *a = ( int* ) malloc ( 5 * sizeof ( int ) ) ;
or :
int x = 5 ;
or, finally, :
tl.sublayertransform = catransform3drotate(t3d, -(callcounter*m_pi) , 1.0, 0.0, 0.0) ;
cause idea of transform property generate matrix, written sublayertransfrom class field. and, compiler, it's same expression, malloc call, or initialising x variable - it's assigment operation. looks like, catransformlayer class has kind of checker, being called if property changes it's value. cocoa automatically send messages when property changes. key-value observation mechanism.
so, animate non-animatable property, decided use catransaction blocks. they're helpfull in such situations. hope, find post useful! sorry english, i'm russia)
Comments
Post a Comment