Iphone 如何在多个Calayer上协调动画时间?

Iphone 如何在多个Calayer上协调动画时间?,iphone,core-animation,Iphone,Core Animation,嗨,我有两个Calayer(*layer1和*layer2)。我想要的是在第二层动画时间超过第二层动画时间的50%时开始第二层动画。我怎样才能做到这一点 我尝试使用CAAnimationGroup,但这只适用于同一层中的动画。我已经找到了一种解决方法,您必须首先将延迟的动画添加到组中,并设置beginTime属性,但这对我来说似乎有点不太成熟,我想知道是否有一种正确的方法来实现我想要的 谢谢大家! 将第二个动画添加到组中的方法确实感觉有点像黑客,但它是有效的,完全可以接受。但是,如果您愿意,您可

嗨,我有两个Calayer(*layer1和*layer2)。我想要的是在第二层动画时间超过第二层动画时间的50%时开始第二层动画。我怎样才能做到这一点

我尝试使用CAAnimationGroup,但这只适用于同一层中的动画。我已经找到了一种解决方法,您必须首先将延迟的动画添加到组中,并设置beginTime属性,但这对我来说似乎有点不太成熟,我想知道是否有一种正确的方法来实现我想要的


谢谢大家!

将第二个动画添加到组中的方法确实感觉有点像黑客,但它是有效的,完全可以接受。但是,如果您愿意,您可以做的是调用性能选择器:withObject:afterDelay。大概是这样的:

- (void)startFirstAnimation;
{
    CGFloat duration = 10.0;

    CABasicAnimation *firstAnim = 
             [CABasicAnimation animationWithKeyPath:@"position"];
    [firstAnim setFromValue:
             [NSValue valueWithCGPoint:CGPointMake(30.0f, 30.0f)]];
    [firstAnim setToValue:
             [NSValue valueWithCGPoint:CGPointMake(200.0f, 200.0f)]];
    [firstAnim setDuration:duration];

    [firstLayer addAnimation:firstAnim forKey:nil];

    [self performSelector:@selector(startSecondAnimation) 
               withObject:nil afterDelay:duration/2.0]; 
}

- (void)startSecondAnimation;
{
    CABasicAnimation *secondAnim = 
             [CABasicAnimation animationWithKeyPath:@"position"];
    [secondAnim setFromValue:
             [NSValue valueWithCGPoint:CGPointMake(100.0f, 30.0f)]];
    [secondAnim setToValue:
             [NSValue valueWithCGPoint:CGPointMake(200.0f, 200.0f)]];
    [secondAnim setDuration:5.0];

    [secondLayer addAnimation:secondAnim forKey:nil];
}