gpt4 book ai didi

ios - 使用AVSynchronizedLayer时动画无法开始

转载 作者:行者123 更新时间:2023-12-01 18:31:14 29 4
gpt4 key购买 nike

我已经设置了一个项目作为测试,使用AVSyncronizedLayer在电影播放时在屏幕上移动红线(CALayer)。

在执行此操作时,我引用了given here答案,并包含了该解决方案,但是当视频播放时动画不会开始。

如果有人对我要去哪里有任何想法,那将非常有帮助。代码是:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

//create the red line sublayer
redLine = [CALayer layer];
redLine.backgroundColor = [UIColor redColor].CGColor;
redLine.frame = CGRectMake(engravingControl.frame.origin.x, engravingControl.center.y - (engravingControl.frame.size.height/2), 3, engravingControl.frame.size.height);


//create the AVplayer object
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"IMG_1306" withExtension:@"mov"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];

AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = CGRectMake(0, 0,400,300);
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

//add the subViews
[self.view.layer addSublayer:playerLayer];
[self.view.layer addSublayer:redLine];

CABasicAnimation *redLineMove;
redLineMove=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
redLineMove.duration=10;
redLineMove.fromValue=[NSNumber numberWithFloat:engravingControl.frame.origin.x];
redLineMove.toValue=[NSNumber numberWithFloat:engravingControl.frame.size.width + engravingControl.frame.origin.x];
redLineMove.beginTime = AVCoreAnimationBeginTimeAtZero;


//create the sync layer
AVSynchronizedLayer *syncLayer = [AVSynchronizedLayer synchronizedLayerWithPlayerItem:playerItem];
[syncLayer addSublayer:redLine];
[redLine addAnimation:redLineMove forKey:@"redLineMove"];

[self.view.layer addSublayer:syncLayer];

[player play];

}

最佳答案

我找到了解决方案。如果您没有以下代码行:

animation.removedOnCompletion = NO;

然后动画就永远不会开始(我想它会在电影开始播放之前由CA删除)。

添加它,它会按预期工作。

关于ios - 使用AVSynchronizedLayer时动画无法开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8554241/

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