0

I have a custom UIView class that I want to spin, shrink and move off screen at a random angle all at the same time.

I have this code that will spin the layer a few times

- (void)spinLayer:(CALayer *)inLayer duration:(CFTimeInterval)inDuration currentAngle:(CGFloat)curAngle
        direction:(int)direction
{
    CABasicAnimation* rotationAnimation;

    // Rotate about the z axis
    rotationAnimation = 
    [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    // Rotate 360 degress, in direction specified
    rotationAnimation.toValue = [NSNumber numberWithFloat:(M_PI * 4 * direction) + curAngle];

    // Perform the rotation over this many seconds
    rotationAnimation.duration = inDuration;

    // Set the pacing of the animation
    rotationAnimation.timingFunction = 
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

    // Add animation to the layer and make it so
    [inLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

which I call like this:

CGFloat angle = atan2(sender.transform.b, sender.transform.a);  // Current angle
[self spinLayer:sender.layer duration:0.5 currentAngle:angle direction:1]; //direction can be -1

But how can I now shrink the view and move it at the same time?

Thanks

Darren
  • 10,182
  • 20
  • 95
  • 162

1 Answers1

1

Rotating a view by 360 degrees yields no animation as the start and end state are identical. You should try using several values for the rotation values.

Felix Lamouroux
  • 7,414
  • 29
  • 46
  • Sorry, I think I edited my question at the same time you must have replied. I have got the rotation working fine now, I just need to rest. – Darren Jun 06 '12 at 15:09
  • I would use one of the more complex animation classes that allow you to set several Values for the animation. – Felix Lamouroux Jun 06 '12 at 15:20
  • How would you spin with the more complex classes? Reading this question http://stackoverflow.com/questions/518530/rotate-a-uiview-around-its-center-but-several-times suggests the method i've used. – Darren Jun 06 '12 at 15:31