3

在执行旋转动画之前,我首先执行 UIImageView 的旋转:

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

然后在视图上调用 180 度旋转......但它似乎是从原始位置开始旋转图像,就好像它最初没有旋转一样。

- (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"];
}

是什么赋予了?

4

2 回答 2

4

rotationAnimation.cumulative = YES;

您是否尝试过使用rotationAnimation.additive = YES;而不是累积?

于 2010-10-19T15:18:54.473 回答
2

您可以使用类方法UIView轻松地为您的视图设置动画:

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

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

[UIView commitAnimation];

这就是我大部分时间都在使用的,不需要使用图层。

更新:我的意思是,我发现在这种情况下不使用图层更容易,使用图层没有贬义。

于 2010-10-19T14:16:05.183 回答