[AVPlayer视频在TableView单元格中滚动时会出现白色边框

问题描述 投票:0回答:1
let scale = UIScreen.main.bounds.width / CGFloat((videoinfo.Width as NSString).floatValue)
                let bestHeight = CGFloat((videoinfo.Height as NSString).floatValue) * scale
                cell.videoViewHeight.constant = bestHeight
                cell.videoView.frame.size.height = bestHeight

                let playerItem = AVPlayerItem(url: URL(string:videoinfo.Filename)!)
                cell.player = AVQueuePlayer(playerItem: playerItem)
            cell.looper = AVPlayerLooper(player: cell.player!, templateItem: playerItem)

            var layer = AVPlayerLayer()
            layer = AVPlayerLayer(player: cell.player)
            layer.backgroundColor = UIColor.white.cgColor
            layer.frame = cell.videoView.bounds
            layer.videoGravity = .resizeAspectFill
            cell.videoView.layer.sublayers?
                .filter { $0 is AVPlayerLayer }
                .forEach { $0.removeFromSuperlayer() }
            cell.videoView.layer.addSublayer(layer)

            cell.player?.play()

正在Tableview单元中播放视频的代码。

请检查视频

https://drive.google.com/open?id=1Vlc21H5UpacUR0V2dhvO-pGAlEMNr8ls

您可以看到,AVPlayer滚动时会奇怪地出现白色边框。

知道是什么原因造成的?

ios swift uitableview avplayer
1个回答
0
投票
可能是AVPlayerLayer在其父视图中未正确调整大小。
© www.soinside.com 2019 - 2024. All rights reserved.