0

機械から出てくる多くの泡をアニメーション化しようとしています。基本的なアニメーションを使用してバブルを小さなバブルから大きなバブルにスケーリングし、キーフレーム アニメーションを使用してバブルを曲線で画面全体に送ります。これらは、グループ アニメーションに結合されます。

これを機能させるためにできる限りのことを読みましたが、次の2つの問題があります。

  1. 各バブルをアニメーション化しようとすると、スケール アニメーションをキーフレーム アニメーションと連携させることができません。
  2. アニメーションはそれらすべてに同時に発生します。次々とアニメ化してほしいのですが、全部一緒にアニメ化してしまいます。

これが私が持っているアニメーションコードです。

-(void)EmitBubbles:(UIButton*)bubblename :(CGRect)RectPassed
{
bubblename.hidden = NO;
 // Set position and size of each bubble to be at head of bubble machine and size (0,0)
CGPoint point = (RectPassed.origin);
CGRect ButtonFrame;
ButtonFrame = bubblename.bounds;
ButtonFrame.size = CGSizeMake(0, 0);
bubblename.bounds = ButtonFrame;
CGRect OldButtonBounds = bubblename.bounds;
CGRect NewButtonBounds = OldButtonBounds;
NewButtonBounds.size = RectPassed.size;

CGFloat animationDuration = 0.8f;

// Set up scaling
CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
resizeAnimation.fillMode = kCAFillModeForwards;
resizeAnimation.duration = animationDuration;
resizeAnimation.fromValue = [NSValue valueWithCGSize:OldButtonBounds.size]; 
resizeAnimation.toValue = [NSValue valueWithCGSize:NewButtonBounds.size]; 

// Set Actual bubble size after animation 
bubblename.bounds = NewButtonBounds;

// Setup Path
CGPoint MidPoint = CGPointMake(500,50);
CGPoint EndPoint = CGPointMake(RectPassed.origin.x, RectPassed.origin.y); 
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, nil, bubblename.bounds.origin.x, bubblename.bounds.origin.y);
CGPoint NewLoc = CGPointMake(745, 200);
CGPathMoveToPoint(curvedPath, NULL, NewLoc.x,NewLoc.y); 
CGPathAddCurveToPoint(curvedPath, NULL, 745,200,MidPoint.x,MidPoint.y, EndPoint.x, EndPoint.y);
pathAnimation.path = curvedPath;

// Set Bubble action position after animation
bubblename.layer.position = point;

// Add scale and path to animation group
CAAnimationGroup *group = [CAAnimationGroup animation];
group.removedOnCompletion = YES;
[group setAnimations:[NSArray arrayWithObjects:pathAnimation, resizeAnimation, nil]];
group.duration = animationDuration;

[bubblename.layer addAnimation:group forKey:@"nil"]; //savingAnimation


CGPathRelease(curvedPath);

}

を使用して、各バブルのアニメーションを呼び出します

[self EmitBubbles:btnbubble1 :CGRectMake(200, 500, 84, 88)];
[self EmitBubbles:btnbubble2 :CGRectMake(200, 500, 84, 88)];

画面に20個の泡があります。渡された四角形のサイズは、泡にしたい最終的なサイズです。

バブルごとに上記のコードを書かなくても、スケールとキーフレーム パスを使用して各バブルを個別にアニメーション化することはできますか?

ありがとう

4

1 に答える 1