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

クラスメソッドfromUIViewを使用して、ビューを簡単にアニメーション化できます。

[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 に答える