13

CABasicAnimation を使用してUIImageView時計回りに 90 度回転させていますが、最初の 90 度回転後の位置から後でさらに 90 度回転させる必要があります。

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 10;
animation.additive = YES;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.fromValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(0)];
animation.toValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(90)];
[_myview.layer addAnimation:animation forKey:@"90rotation"];

上記のコードを使用すると、最初は機能し、画像は 90 度の角度のままになります。これをもう一度呼び出してさらに 90 度回転させると、アニメーションは 0 に戻り、90 度から 180 度ではなく 90 度回転することから始まります。

animation.additive = YES;今後のアニメーションで現在の状態を出発点として使用するという印象を受けました。

何か案は?

4

2 に答える 2

6

角度の増分値を渡す 私のコードを参照してください

static int imgAngle=0;
- (void)doAnimation
{
  CABasicAnimation *animation = [CABasicAnimation   animationWithKeyPath:@"transform.rotation.z"];
   animation.duration = 5;
  animation.additive = YES;
  animation.removedOnCompletion = NO;
  animation.fillMode = kCAFillModeForwards;
  animation.fromValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(imgAngle)];
  animation.toValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(imgAngle+90)];
 [self.imgView.layer addAnimation:animation forKey:@"90rotation"];

  imgAngle+=90;
  if (imgAngle>360) {
      imgAngle = 0;
  }
}

上記のコードは単なるアイデアです。テストされていません

于 2013-07-02T13:47:34.067 に答える