AVSynchronizedLayer不同步动画

编程入门 行业动态 更新时间:2024-10-24 20:17:05
本文介绍了AVSynchronizedLayer不同步动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在制作动画使用AVPlayer时间而不是系统时间的问题。同步层不能正常工作和动画保持上的系统时间,而不是玩家的时间同步。我知道球员确实发挥。如果我通过CACurrentMediaTime()到BEGINTIME,动画马上开始,因为它应该在不同步的。

修改

我可以看到从一开始就在其最终状态红色正方形,这意味着动画的开头到结束,因为它是系统时间同步,而不是AVPlayerItem时间。

//扮演组成生活,以修饰符    AVPlayerItem * playerItem = [AVPlayerItem playerItemWithAsset:【组成】;    AVPlayer *玩家= [AVPlayer playerWithPlayerItem:playerItem];    AVPlayerLayer * playerLayer = [AVPlayerLayer playerLayerWithPlayer:播放器];    playerLayer.frame = [UIScreen mainScreen] .bounds;    如果(!playerItem){        的NSLog(@playerItem空);    }    //设定时间    playerItem.forwardPlaybackEndTime = totalDuration;    playerItem.videoComposition = videoComposition;    CALayer的* aLayer = [CALayer的层]    aLayer.frame = CGRectMake(100,100,60,60);    aLayer.backgroundColor =的UIColor redColor] .CGColor;    aLayer.opacity = 0.f;    CAKeyframeAnimation * keyframeAnimation2 = [CAKeyframeAnimation animationWithKeyPath:@不透明度];    keyframeAnimation2.removedOnCompletion = NO;    keyframeAnimation2.beginTime = 0.1;    keyframeAnimation2.duration = 4.0;    keyframeAnimation2.fillMode = kCAFillModeBoth;    keyframeAnimation2.keyTimes = @ [@ 0.0,@ 1.0]。    keyframeAnimation2.values​​ = @ [@ 0.f,@ 1.F]    的NSLog(@%F当前媒体时间,CACurrentMediaTime());    [aLayer addAnimation:keyframeAnimation2                  forKey:@不透明度];    [self.parentLayer addSublayer:aLayer];    AVSynchronizedLayer * synchronizedLayer =    [AVSynchronizedLayer synchronizedLayerWithPlayerItem:playerItem];    synchronizedLayer.frame = [UIScreen mainScreen] .bounds;    [synchronizedLayer addSublayer:self.parentLayer];    [playerLayer addSublayer:synchronizedLayer];

解决方案

解决的办法是, AVSynchronizedLayer 不会在模拟器上工作,但在设备上正常工作。

I'm having issues making the animation use the AVPlayer time instead of the system time. the synchronized layer does not work properly and animations stay synchronized on the system time instead of the player time. I know the player do play. and if I pass CACurrentMediaTime() to the beginTime, the animation start right away as it should when not synchronized.

EDIT

I can see the red square in its final state since the beginning, which mean the animation has reach its end at the beginning because it is synchronized on the system time and not the AVPlayerItem time.

// play composition live in order to modifier AVPlayerItem * playerItem = [AVPlayerItem playerItemWithAsset:composition]; AVPlayer * player = [AVPlayer playerWithPlayerItem:playerItem]; AVPlayerLayer * playerLayer = [AVPlayerLayer playerLayerWithPlayer:player ]; playerLayer.frame = [UIScreen mainScreen].bounds; if (!playerItem) { NSLog(@"playerItem empty"); } // dummy time playerItem.forwardPlaybackEndTime = totalDuration; playerItem.videoComposition = videoComposition; CALayer * aLayer = [CALayer layer]; aLayer.frame = CGRectMake(100, 100, 60, 60); aLayer.backgroundColor = [UIColor redColor].CGColor; aLayer.opacity = 0.f; CAKeyframeAnimation * keyframeAnimation2 = [CAKeyframeAnimation animationWithKeyPath:@"opacity"]; keyframeAnimation2.removedOnCompletion = NO; keyframeAnimation2.beginTime = 0.1; keyframeAnimation2.duration = 4.0; keyframeAnimation2.fillMode = kCAFillModeBoth; keyframeAnimation2.keyTimes = @[@0.0, @1.0]; keyframeAnimation2.values = @[@0.f, @1.f]; NSLog(@"%f current media time", CACurrentMediaTime()); [aLayer addAnimation:keyframeAnimation2 forKey:@"opacity"]; [self.parentLayer addSublayer:aLayer]; AVSynchronizedLayer * synchronizedLayer = [AVSynchronizedLayer synchronizedLayerWithPlayerItem:playerItem]; synchronizedLayer.frame = [UIScreen mainScreen].bounds; [synchronizedLayer addSublayer:self.parentLayer]; [playerLayer addSublayer:synchronizedLayer];

解决方案

The solution was that AVSynchronizedLayer doesn't work on the Simulator but works fine on a device.

更多推荐

AVSynchronizedLayer不同步动画

本文发布于:2023-10-26 19:07:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531084.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不同步   动画   AVSynchronizedLayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!