2016-05-26 32 views
0

私はAVPlayerLayerの境界で追加アニメーションを実行しようとしています。単にadditiveをYESに設定すると、アニメーションが壊れます。幅と高さが異なるアニメーションパラメータでアニメーション化できるように、私はそれを追加する必要があります。キーパスbounds.size.widthとbounds.size.heightをアニメートするとどちらも機能しません。AVPlayerLayer境界で追加アニメーションを使用するにはどうすればよいですか?

私は他のCALayerクラスを下のコードでうまく動かすことができるので、AVPlayerLayerにバグがあるかどうか疑問に思います。ここで

コードです:赤のエリアは、ビデオの再生でなければなりません

enter image description here

AVPlayerLayer *vl; 

// ... 


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 

    NSURL *path = [[NSBundle mainBundle] URLForResource:@"vid" withExtension:@"mp4"]]; 
    AVPlayer *player = [AVPlayer playerWithURL: path]; 
    vl = [AVPlayerLayer playerLayerWithPlayer:player]; 
    vl.videoGravity = AVLayerVideoGravityResize; 
//  vl = [CALayer layer]; // a normal calayer animates properly 

    vl.backgroundColor = [NSColor redColor].CGColor; 
    vl.frame = CGRectMake(200,100,150,100); 
    [_window.contentView.layer addSublayer:vl]; 
} 

- (IBAction)animate:(id)sender { 
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"]; 
    animation.fromValue = [NSValue valueWithRect:CGRectMake(0,0,0, 0)]; 
    animation.toValue = [NSValue valueWithRect:CGRectMake(0,0,240, 60)]; 
    animation.duration = 4; 
    animation.additive = YES; 

    [vl addAnimation:animation forKey:nil]; 
} 

これは、次のようになります。

あなたは私がここで作成したサンプルプロジェクトをチェックアウトすることができます: https://www.dropbox.com/s/jxuh69wiqdwnuc6/PlayerLayer%20size%20Animation.zip?dl=1

答えて

0

CALayerのフレームプロパティは、位置、anchorPointに依存し、派生プロパティで境界と層の変換。フレームをアニメートする代わりに、達成しようとしている効果に応じて、positionまたはboundsをアニメーション化する必要があります。

Q: When I try to animate the frame of a CALayer nothing happens. Why?

これはまた助けることができる: How to animate the frame of an layer with CABasicAnimation?

をそして、それらのコードはあなたにhelpulことがあります

あなたはまずこれを見てとることが

NSURL *fileUrl = [NSURL fileURLWithPath:@"yourFilePath"]; 
AVPlayer *player = [[AVPlayer alloc] initWithURL:fileUrl]; 

CALayer *superlayer = self.view.layer; 
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; 
[superlayer addSublayer:playerLayer]; 

[player play]; 

playerLayer.videoGravity = AVLayerVideoGravityResize; 
playerLayer.frame = CGRectMake(10, 200, 320, 200); 
playerLayer.position = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2); 

CGRect startBounds = CGRectMake(10, 200, 200, 150); 
CGRect endBounds = CGRectMake(10, 200, 320, 200); 

CABasicAnimation * sizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"]; 

sizeAnimation.fromValue = [NSValue valueWithRect:startBounds] ; 
sizeAnimation.toValue = [NSValue valueWithRect:endBounds] ; 
sizeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 
sizeAnimation.duration = 4; 

[playerLayer addAnimation:sizeAnimation forKey:@"bounds"]; 
+1

コードをフレーム内ではなく、アニメーションの境界であるという問題である。元の質問のコード例は、通常のCALayersのために働くので、AVPlayerLayersに特有のクールなようです。 – Hooper

+0

元の質問のコード例は境界もアニメーション化しています!あなたはCALayerのフレームをアニメートできないからです! – Stoull

関連する問題