views:

108

answers:

2

I added a CATransform3DMakeRotation to a layer. When I add another one it deletes the old one?

The first one:

[UIView beginAnimations:@"rotaty" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self]; 
CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14);
kuvert.transform = CGAffineTransformRotate(transform, DegreesToRadians(134));
kuvert.center = CGPointMake(kuvert.center.x-70, kuvert.center.y+100);
[UIView commitAnimations];

and the second one:

CABasicAnimation *topAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
topAnim.duration=1;
topAnim.repeatCount=0;
topAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 0, 0, 0)];
float f = DegreesToRadians(180);  // -M_PI/1;
topAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(f, 0,1, 0)];
topAnim.delegate = self;
topAnim.removedOnCompletion = NO;
topAnim.fillMode = kCAFillModeBoth;
[topAnim setValue:@"flippy" forKey:@"AnimationName"];
[[KuvertLasche layer] addAnimation:topAnim forKey:@"flippy"];

The second one resets the view and applies itself after that. How do I fix this??

A: 

I found out I can do it with topAnim.additive =YES; Thanks anyway!

david
A: 

Yes, CATransform3DMakeRotation() will create a brand-new transform which overwrites the existing one. If you want to modify the existing transform, you should use CATransform3DRotate(). For example, you could modify your second code sample with the lines

CATransform3D existingTransform = [[KuvertLasche layer] transform];
topAnim.fromValue = [NSValue valueWithCATransform3D:existingTransform];
float f = DegreesToRadians(180);  // -M_PI/1;
topAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DRotate(existingTransform, f, 0,1, 0)];

Note that if one animation is to perform after another, you will need to use delegate callbacks to start the second once the first is finished. Animations are performed on a background thread, so if both of your animations defined above are fired off one after the other, the results could be a mess.

Brad Larson