2013-04-09 3 views
0

은 할 수 있습니다 :레이어를 다시 뒤집을 수 없습니다. CALayer, CATransform3DRotate. 내가 뭘하려고 오전

  1. 수직 플립을 할 수있는 botton을을 클릭합니다.

코드는 다음과 같습니다 ... 레이어가 다시 등을 뒤집어 줘야 해, 다시 botton을 클릭 :

@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; 
    } 

그러나, 1 단계에서, 나는 레이어 플립을 볼 수 있습니다 (180) 버튼을 다시 클릭하면 아무 일도 일어나지 않습니다.

중간에 뭔가 놓쳤습니까? 도와주세요.

+1

플립 백이 0이되어서는 안됩니까? 180.0에서 -180으로 (또는 그 반대로) 전환하면 360 도가됩니다. – Rob

답변

1

아래 코드는 보낸 사람이 선택한 상태 만 가져옵니다. 그리고 상태는 한 번만 설정됩니다. 아래 수정 코드를 확인하십시오.

// Have a 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 ALSO BE 0 
     isClicked      = false; 
     } 
     plane.transform     = transfrom; 
    } 
+1

'CATransform3DIdentity'에 할당하는 것이 훨씬 효과적이지 않습니까? – CodaFi

+0

그래, 왜 안돼. 필요한 경우 @ttran을 사용하여 3d 애니메이션을 만듭니다. http://stackoverflow.com/questions/5606467/using-catransform3d-to-create-flip-animation –