Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use two different UIViewAnimationCurves in the same animation

I want to be able to use one UIViewAnimationCurve for rotations and another for changes in position. Is this possible?

For example (in pseudo code);

// Begin animations

// Set rotation animation curve to EaseInOut

// Set position animation curve to Linear

// Make some changes to position

// Make some change to the angle of rotation

// Commit the animations

EDIT: (CAAnimationGroup approach suggested below) - Have created 2 separate CABasicAnimations and a CAAnimationGroup however the animations are not starting. Any ideas?

CABasicAnimation *postionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
postionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
postionAnimation.toValue = [NSValue valueWithCGPoint:[self transformPointToWorldSpaceFromViewSpace:self.spriteView.position]];
postionAnimation.delegate = self;

CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.z"];
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotationAnimation.toValue = [NSNumber numberWithFloat:self.spriteView.angle -= M_PI_2];
rotationAnimation.delegate = self;

CAAnimationGroup *animationsGroup = [CAAnimationGroup animation];
animationsGroup.duration = self.clockSpeed;
animationsGroup.animations = [NSArray arrayWithObjects:postionAnimation, rotationAnimation, nil];

// Perform the animation
[self.spriteView.layer addAnimation:animationsGroup forKey:nil];
like image 589
Magic Bullet Dave Avatar asked Jul 12 '12 09:07

Magic Bullet Dave


1 Answers

Try by creating two different animations. With method of UIView you can't set different animationsCurves for different properties of your animation. Or you can have fun with CAAnimations and create a CAAnimationGroup in which you set your two CABasicAnimation

like image 104
iSofTom Avatar answered Oct 13 '22 01:10

iSofTom