gpt4 book ai didi

ios - AVSynchronizedLayer 不同步动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:07:57 25 4
gpt4 key购买 nike

我在制作动画时使用 AVPlayer 时间而不是系统时间时遇到问题。同步层无法正常工作,动画在系统时间而不是播放器时间上保持同步。我知道玩家确实在玩。如果我将 CACurrentMediaTime() 传递给 beginTime,动画会立即开始,因为它应该在不同步时开始。

编辑

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

    // 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];

最佳答案

解决方案是 AVSynchronizedLayer 在模拟器上不起作用,但在设备上运行良好。

关于ios - AVSynchronizedLayer 不同步动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19707985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com