18

CGPathに基づいてCALayerの位置をアニメートしたいのですが、逆方向に再生したいと思います。

パスを逆方向にアニメーション化する方法、またはCGPathを逆方向にする方法はありますか?

4

2 に答える 2

31
animation.speed = -1;

?

于 2010-01-15T18:54:48.923 に答える
4

これは最善の解決策ではないかもしれませんが、私にとってはうまくいきました。私はアニメーションに自動反転を指示し、途中で開始しました。

- (void) animate {
    CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.path = path;
    pathAnimation.duration = 15.0;
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.timeOffset = pathAnimation.duration;
    pathAnimation.autoreverses = YES;

    NSString * key = @"pathAnimation";
    [animatedView.layer addAnimation:pathAnimation forKey:key];
    [NSTimer scheduledTimerWithTimeInterval:pathAnimation.duration target:self selector:@selector(endAnimation:) userInfo:key repeats:NO];
}

- (void) endAnimation:(NSTimer *)timer {
    [animatedView.layer removeAnimationForKey:timer.userInfo];
}

もっと良い方法があれば、知りたいです。

于 2010-01-15T18:22:55.633 に答える