1

CAKeyframeAnimationを使用して、アプリでいくつかのアニメーションを実行しています。アニメーションと一緒にオーディオファイルを再生したいのですが(途中、場合によっては後)。どうすればこれを達成できますか?CAKeyframeAnimation用のAnimationDidStopSelectorはありますか、それともこれを行うための別のアプローチがありますか?

UIBezierPath *movePath = [UIBezierPath bezierPath];
            [movePath moveToPoint:imageAnimation.center];
            [movePath addQuadCurveToPoint:CGPointMake(839, 339)
                             controlPoint:CGPointMake(671, 316)];

            CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
            moveAnim.path = movePath.CGPath;
            CAAnimationGroup *animGroup = [CAAnimationGroup animation];
            animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil];
            animGroup.duration = 0.5;
            imageAnimation.layer.position = CGPointMake(839, 339);
            imageAnimation.tag = 0;
            [imageAnimation.layer addAnimation:animGroup forKey:nil];
            break;
4

1 に答える 1

0

実はあります。最初に自分自身をデリゲートとして割り当てます。

animGroup.delegate = self

異なるアニメーションを使用する場合は、KVC を使用してそれらを区別できます。

[yourAnimation setValue:@"firstAnimation" forKey:@"animationName"];

次に、このメソッドを実装します

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
    if (flag && [[anim valueForKey:@"animationName"] isEqualToString:@"firstAnimation"]) {
        //play your sound
    }
    else if (flag && [[anim valueForKey:@"animationName"] isEqualToString:@"secondAnimation"]) {
        //do something else
    }
}
于 2011-09-26T16:04:55.183 に答える