ios - Cannot flip layer again,CALayer,CATransform3DRotate. -
what trying do :
- click botton vertical flip.
- click botton again, layer wil flip , on...
codes following :
@interface viewcontroller (){ calayer *plane; } @end @implementation viewcontroller -(void)viewdidload { [super viewdidload]; [self addalayer]; } - (void)addalayer{ plane = [calayer layer]; plane.backgroundcolor = [[uicolor orangecolor] cgcolor]; //[plane insertsublayer:normalbackground atindex:0]; plane.opacity = 1; plane.frame = cgrectmake(0, 0, 300, 100); plane.position = cgpointmake(250, 150); plane.anchorpoint = cgpointmake(0.5, 0.5); plane.bordercolor = [uicolor whitecolor].cgcolor; plane.borderwidth = 3; plane.cornerradius = 10; [self.view.layer addsublayer:plane]; } - (ibaction)click:(id)sender { bool isclicked = ((uibutton*)sender).selected; ((uibutton*)sender).selected = !((uibutton*)sender).selected; catransform3d transfrom = catransform3didentity; transfrom.m34 = -1.0/ 500; if ( !isclicked ) transfrom = catransform3drotate(transfrom, degtorad(180.0), 1, 0, 0); else transfrom = catransform3drotate(transfrom, degtorad(-180.0), 1, 0, 0); plane.transform = transfrom; }
however, @ step 1, can see layer flip 180 degree , when click button again, there nothing happening.
did miss in middle? please help.
the code below gets sender's selected state only. , state set once. check modified code below.
// have global variable bool isclicked - (ibaction)click:(id)sender { catransform3d transfrom = catransform3didentity; transfrom.m34 = -1.0/ 500; if ( !isclicked ) { transfrom = catransform3drotate(transfrom, degtorad(180.0), 1, 0, 0); isclicked = true; } else{ transfrom = catransform3drotate(transfrom, degtorad(360.0), 1, 0, 0); // or can 0 isclicked = false; } plane.transform = transfrom; }
Comments
Post a Comment