开发者

CGAffineTransformMakeRotation before a CABasicAnimation

开发者 https://www.devze.com 2023-01-20 15:51 出处:网络
I\'m performing a rotation of an UIImageView in place first before performing a rotation animation: // rotate to the left by 90 degrees

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?


rotationAnimation.cumulative = YES;

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消