将按钮放在 PlayerLayer - Swift - 以编程方式

Put buttons over PlayerLayer - Swift - Programmatically

我有一个 UIView,它应该使用 AVPlayerLayer 和 AVPlayer 播放视频。 我是这样设置播放器的:

fileprivate func setUpPlayer(){
 
            let urlPathString = Bundle.main.path(forResource: "dance", ofType: "mp4")

            if let videoURL = urlPathString{

                let url = URL(fileURLWithPath: videoURL)
                player = AVPlayer(url: url)
                playerLayer = AVPlayerLayer(player: player)

               
                playerLayer.videoGravity = .resizeAspectFill
                
                self.playerView.layer.addSublayer(playerLayer)
                
                
                self.playerView.layer.masksToBounds = true
           
    }
}

override func layoutSubviews() {
    self.layer.cornerRadius = 15
    playerLayer.frame = self.bounds
    self.setupShadow(opacity: 0.6, radius: 6, offset: CGSize.init(width: 0, height: 0), color: .darkGray)
}

问题是无论我在 PlayerView 上设置了多少个子视图,视频实际上遍历了所有内容,隐藏了我之前设置的所有子视图。

你知道我如何将按钮或其他 UIView 放在 AVPlayerLayer 上而不实际隐藏它们吗?

改变

self.playerView.layer.addSublayer(playerLayer)

self.playerView.layer.insertSublayer(playerLayer, at: 0)