views:

18

answers:

2

I'm performing a rotation of an UIImageView in place first before performing a rotation animation:

// rotate to the left by 90 degrees
        someView.transform = CGAffineTransformMakeRotation((-0.5)*M_PI);

Then calling a rotation on the view by 180 degrees... but it seems like it is rotating the image starting from the original position as if it was not initially rotated.

- (void)rotateIndicatorToAngle: (UIView *)view angle: (NSNumber *)angleInDegrees
{
    CALayer *layer = view.layer;
    CGFloat duration = 5.0;
    CGFloat radians = [self ConvertDegreesToRadians: [angleInDegrees floatValue]];
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: radians];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0;
    rotationAnimation.removedOnCompletion = NO;
    rotationAnimation.fillMode = kCAFillModeForwards;
    rotationAnimation.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseOut];

[layer addAnimation: rotationAnimation forKey: @"rotationAnimation"];
}

What gives?

A: 

You could use the class methods from UIView to easily animate your view:

[UIView beginAnimation: @"Rotate" context: nil];
[UIView setAnimationDuration: 5.0f];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];

CGFloat radians = [self ConvertDegreesToRadians: [angleInDegrees floatValue]];
view.transform = CGAffineTransformMakeRotation(radians);

[UIView commitAnimation];

That's what I'm using most of the time, no need to use layers.

UPDATE: I mean, I find it easier not to use layers in that case, no pejorative value on using layers.

jv42
thx for advice, but not a solution to my problem. I'm basically trying to understand why my example fails.
Floetic
OK, see my comment in the other answer for an idea.
jv42
+1  A: 

rotationAnimation.cumulative = YES;

Have you tried using rotationAnimation.additive = YES; instead of cumulative?

jv42