2012-07-13 2 views
1

CAAnimationGroup에 문제가 있습니다. 나는 animeView이라는 뷰를 가지고 있으며 동시에 Y 축을 중심으로 3D 회전과 스케일링 변환을 적용하려고합니다. 회전 및 크기 조정 애니메이션은 완벽하게 작동합니다. ! 그러나 내가 그들을 CAAnimationGroup에 추가 할 때 애니메이션이 아닌 것이 발생합니다!CAAnimationGroup이 작동하지 않습니다.

무엇이 문제인가?

CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation]; 
CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f); 
rotationTransform.m34 = 1.0/-500; 

rotation.values = [NSArray arrayWithObjects: 
        [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 1.0f, 0.0f)], 
        [NSValue valueWithCATransform3D:rotationTransform], 
        [NSValue valueWithCATransform3D:CATransform3DMakeRotation(2.0*M_PI, 0.0f, 1.0f, 0.0f)] ,nil]; 

CAKeyframeAnimation *trans = [CAKeyframeAnimation animation]; 

trans.values = [NSArray arrayWithObjects:[NSValue valueWithCATransform3D:CATransform3DIdentity],[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5, 0.5, 0.5)],[NSValue valueWithCATransform3D:CATransform3DIdentity], nil]; 

CAAnimationGroup *group = [CAAnimationGroup animation]; 

group.delegate = self; 
[group setAnimations: [NSArray arrayWithObjects:rotation, trans, nil]]; 
group.duration = 2; 
group.repeatCount = 3; 

[self.animView.layer addAnimation:group forKey:nil]; 
+0

을 당신은 결코 당신이 애니메이션되는 키 경로를 설정하지 않습니다. 또한 변환을 두 번 애니메이션으로 적용하면 안됩니다. –

+0

키 - 경로를 여기에서 이해할 수 없습니다. 애니메이션의 레이블과 같은 것입니까? 그것은 각 종류의 변환에 특유한 것이어야합니까? – Armin

+0

Btw 나는 두 번 애니메이션 변환 아니에요. CAAnimationGroup을 사용하는 이유는 이것들이 동시에 발생하기로되어 있기 때문입니다! – Armin

답변

2

제공 한 코드에는 두 가지 이상한 점이 있습니다.

  1. 애니메이션 &

    은 변화되어야 하는지를 재산 모르는
  2. 두 애니메이션은 변환 변화 (키와 경로가 설정되어 있지 않은) (실제로 사용되어야 어떤 가치인가?)

방법은 동일한 값 (3)을 가진 두 개의 변환 키 프레임 애니메이션이 있음을 알 수 있습니다. 따라서 전체 변형 행렬 (하나의 행렬에서 축척 및 회전)을 계산하고 해당 애니메이션을보기에만 추가해야합니다.

그것은 (나는 일이 무엇 동생을 설명하는 코멘트를 많이 추가 한)과 같이 보일 것입니다 :

// Your first rotation is 0 degrees and no scaling 
CATransform3D beginTransform = CATransform3DIdentity; 

// Your middle rotation is the exact one that you provided ... 
CATransform3D middleTransform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f); 
// ... but the rotation matrix is then scaled as well ... 
middleTransform = CATransform3DScale(middleTransform, 0.5, 0.5, 0.5); 
// ... and the perspective is set 
middleTransform.m34 = 1.0/-500; 

// Your end value is rotated but not scaled 
CATransform3D endTransform = CATransform3DMakeRotation(2.0*M_PI, 0.0f, 1.0f, 0.0f); 

// Create a new animation that should animate the "transform" property (thus the key path "transform") 
CAKeyframeAnimation *rotateAndScale = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; 
// same configurations as your group had 
[rotateAndScale setDuration:2.0]; 
[rotateAndScale setRepeatDuration:3.0]; 
[rotateAndScale setDelegate:self]; 
// Set the values of the transform animation (yes, both scaling and rotation in one animation) 
[rotateAndScale setValues:[NSArray arrayWithObjects: 
          [NSValue valueWithCATransform3D:beginTransform], 
          [NSValue valueWithCATransform3D:middleTransform], 
          [NSValue valueWithCATransform3D:endTransform], nil]]; 

// Add the animation to the layer, no need for a group here... 
[animView.layer addAnimation:rotateAndScale forKey:nil]; 
+0

데이비드 감사합니다, 나는 그것이 지금 훨씬 더 잘 작동하는 방법을 이해합니다. – Armin