0

我正在尝试为机器中出现的许多气泡设置动画。我正在使用基本动画将气泡从小气泡缩放到大气泡,并使用关键帧动画以曲线形式将气泡发送到屏幕上。这些被组合成一个组动画。

我已经阅读了几乎所有内容以尝试使其正常工作,但是我遇到了以下两个问题。

  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

0

好的。我想我做到了。在查看 Stackoverflow 和其他地方几个小时后,我发现让对象一个接一个地动画。我不得不根据应用时间计算时间。我用了。

group.beginTime = CACurrentMediaTime() + AnimationDelay

在继续动画之前停止动画暂时出现在其最终位置。我不得不使用

group.fillMode = kCAFillModeBackwards;

于 2013-08-22T03:29:14.983 回答