2012-05-04 2 views
2

複数のスプライトシートと期間を取るFrameChangeAnimationクラスがあります。だから私は3つのspritesheetそれぞれの文字の16ブロックを含んでいると言うと、私は '3'秒の時間を与える。 CALayerとしてFrameChangeAnimationインスタンスが返されたら、それを画面にアタッチしてスムーズに再生します[0126]。CFBasicAnimationのカスタムキーを使用したアニメーションは、ビデオのエクスポート時には機能しません。

今このアニメーションをビデオとして書き出します。問題は、今回私はCABasicAnimationを持続時間で付け加えます。 'Duration'パラメータが機能せず、すべてのフレームが1秒間に再生されます。 AVVideoCompositionCoreAnimationToolクラスのドキュメントによると

GTAnimation *an = [[GTAnimation alloc] initWithFrame:CGRectMake(0, 0, videoSize.width, videoSize.height) withFileName:@"Host_Angry_" withSeconds:3.5]; 

    CALayer *animationLayer = [CALayer layer]; 
    animationLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height); 
    [animationLayer addSublayer:an.animLayer]; 

    CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"currentFrame"]; 
    fadeAnimation.fromValue = [NSNumber numberWithFloat:1.0]; 
    fadeAnimation.toValue = [NSNumber numberWithFloat:45.0]; 
    fadeAnimation.additive = NO; 
    fadeAnimation.removedOnCompletion = NO; 
    fadeAnimation.beginTime = 0.0; 
    fadeAnimation.duration = 3.5; 
    fadeAnimation.repeatCount = HUGE_VAL; 
    fadeAnimation.fillMode = kCAFillModeBoth; 
    [an.animLayer addAnimation:fadeAnimation forKey:@"currentFrame"]; 

    CALayer *parentLayer = [CALayer layer]; 
    CALayer *videoLayer = [CALayer layer]; 

    videoLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height); 
    [parentLayer addSublayer:videoLayer]; 
    [parentLayer addSublayer:animationLayer]; 
    videoLayer.anchorPoint = CGPointMake(0.5, 0.5); 
    videoLayer.position = CGPointMake(CGRectGetMidX(parentLayer.bounds), CGRectGetMidY(parentLayer.bounds)); 
    animationLayer.anchorPoint = CGPointMake(0.5, 0.5); 
    animationLayer.position = CGPointMake(CGRectGetMidX(parentLayer.bounds), CGRectGetMidY(parentLayer.bounds)); 
    videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; 

答えて

3

、あなたがしなければならないので、「任意のアニメーションは、ビデオのタイムラインではなく、リアルタイムに解釈されます:

セットアニメーション開始時間プロパティに1E-100ではなく0(CoreAnimationがCACurrentMediaTimeで置換する);

0

使用AVCoreAnimationBeginTimeAtZero代わりfadeAnimation.begintime = 0.0を行う。

fadeAnimation = AVCoreAnimationBeginTimeAtZero; 
関連する問題