5

1つのUIViewAnimationCurveを回転に使用し、もう1つを位置の変更に使用できるようにしたいと思います。これは可能ですか?

たとえば(擬似コードで);

// Begin animations

// Set rotation animation curve to EaseInOut

// Set position animation curve to Linear

// Make some changes to position

// Make some change to the angle of rotation

// Commit the animations

編集:(以下に提案するCAAnimationGroupアプローチ)-2つの別々のCABasicAnimationsとCAAnimationGroupを作成しましたが、アニメーションが開始されていません。何か案は?

CABasicAnimation *postionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
postionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
postionAnimation.toValue = [NSValue valueWithCGPoint:[self transformPointToWorldSpaceFromViewSpace:self.spriteView.position]];
postionAnimation.delegate = self;

CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.z"];
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotationAnimation.toValue = [NSNumber numberWithFloat:self.spriteView.angle -= M_PI_2];
rotationAnimation.delegate = self;

CAAnimationGroup *animationsGroup = [CAAnimationGroup animation];
animationsGroup.duration = self.clockSpeed;
animationsGroup.animations = [NSArray arrayWithObjects:postionAnimation, rotationAnimation, nil];

// Perform the animation
[self.spriteView.layer addAnimation:animationsGroup forKey:nil];
4

3 に答える 3

4

2つの異なるアニメーションを作成してみてください。UIViewのメソッドでは、アニメーションのさまざまなプロパティにさまざまなanimationsCurvesを設定することはできません。または、CAAnimationsを楽しんで、2つのCABasicAnimationを設定するCAAnimationGroupを作成することもできます。

于 2012-07-12T09:41:59.660 に答える
3

最善の策は、animateWithDuration:delay:options:animations:completion:への複数の呼び出しを使用することです。呼び出しごとに異なるアニメーション曲線を使用すると、それらは並行して実行されます。または、異なる遅延値を使用して、それらを順番に実行することができます。

コードは次のようになります。

[UIView animateWithDuration: .5 
  delay: 0
  options: UIViewAnimationOptionCurveEaseInOut 
  animations: ^{
    view1.center = CGPointMake(x, y);
  }
  completion:  ^{
    //code that runs when this animation finishes
  }
];

[UIView animateWithDuration: .5 
  delay: .5
  options: UIViewAnimationOptionCurveLinear
  animations: ^{
    view2.center = CGPointMake(x2, y2);
  }
  completion:  ^{
    //code that runs when this animation finishes
  }
];

CAAnimationGroupsを使用する場合、いくつかの問題があります。

まず、アニメーショングループがグループ全体のアニメーション曲線を決定します。サブアニメーションごとに異なる曲線を指定できるとは思いません(ただし、試したことはありません)。

次に、アニメーションをグループに追加した場合、個々のアニメーションのデリゲートは呼び出されません。アニメーショングループのデリゲートメソッドのみが呼び出されます。

于 2012-07-14T01:41:09.187 に答える
0

わかりました、最終的にそれを解決しました。iSofTomの方向性に感謝します(あなたの答えに投票しました)。私は個々のアニメーションの代表者を設定しましたが、グループは設定しませんでした。

CABasicAnimation *postionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
postionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
postionAnimation.fromValue = [NSValue valueWithCGPoint:self.spriteView.center];
postionAnimation.toValue = [NSValue valueWithCGPoint:[self transformPointToViewSpaceFromWorldSpace:self.spriteView.position]];

CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotationAnimation.fromValue = [NSNumber numberWithFloat:self.spriteView.angle];
rotationAnimation.toValue = [NSNumber numberWithFloat:self.spriteView.rotation];

CAAnimationGroup *animationsGroup = [CAAnimationGroup animation];
animationsGroup.duration = self.clockSpeed;
animationsGroup.animations = [NSArray arrayWithObjects:postionAnimation, rotationAnimation, nil];
animationsGroup.delegate = self;
// Perform the animation
[self.spriteView.layer addAnimation:animationsGroup forKey:nil];

- (void)animationDidStart:(CAAnimation *)theAnimation {
radiansToDegrees(self.spriteView.rotation));
    self.spriteView.angle = self.spriteView.rotation;

NSStringFromCGPoint(self.spriteView.position));
    self.spriteView.center = [self transformPointToViewSpaceFromWorldSpace:self.spriteView.position];
}
于 2012-07-12T21:12:44.707 に答える