设置AVPlayerLayer的不透明度 [英] Set opacity of AVPlayerLayer
问题描述
我已经看到很多人想播放具有透明背景的视频的帖子.那不是我要在这里完成的.
I have seen quite a few posts of people wanting to play videos with transparent backgrounds. That is not what I am trying to accomplish here.
我正在尝试设置整个图层的不透明度.以下是我如何设置图像图层的不透明度.我尝试了相同的方法来设置视频层的不透明度,但是当我尝试淡入淡出时
I am trying to set the opacity of the whole layer. Below is how I am setting the opacity of an image layer. I have tried the same approach to set opacity for the video layer but nothing happened when I attempted to fade
@IBAction func imageFadeAction(_ sender: Any) {
let rounded = Int(round(imageFader.value))
imageLabel.text = "\(rounded.description)%"
let fade = imageFader.value / 100
SecondScreen.main?.backgroundImage.alpha = CGFloat(fade)
SecondScreen.main?.viewDidLoad()
}
这就是我播放视频并生成图层的方式
This is how I am playing the video and generating the layer
func playVideo() {
let videoURL = SecondScreen.videoPath
self.player = AVPlayer(url: videoURL!)
self.avpController = AVPlayerLayer(player: player)
avpController.frame = self.view.bounds
self.view.layer.addSublayer(avpController)
player.play()
}
任何人都可以告诉我是否可行或将我指向正确的方向
Can anyone tell me if its possible or point me in the right direction
推荐答案
要回答我自己的问题,请使用容器视图.在单独的ViewController中播放视频并将其嵌入到容器视图中.然后,您可以设置容器视图的不透明度.
To answer my own question, Use a container view. play your video in a separate ViewController and embed it in the container view. THEN you can set the opacity of the container view.
我不知道这是否是正确的方法,但是它对我有用,并且对我有用.如果有人有更好的答案,请随时分享
I don't know if this is the correct way to do it, but it works for me and what I needed. If someone has a better answer please feel free to share
这篇关于设置AVPlayerLayer的不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!