我试图在AVPlayerLayer
顶部添加一个播放按钮,但未显示。
我有一个名为UIView
的playerView
作为IBOutlet。
这是创建player
和相应的playerLayer
并将其放入playerView
的方法:
player = AVPlayer()
superLayer = self.playerView.layer
playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.playerView.bounds
playerLayer.cornerRadius = 5.0
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
superLayer.addSublayer(playerLayer)
self.view.bringSubview(toFront: playVideoButton)
问题在于
playVideoButton
不会显示在playerLayer
的顶部(在情节提要中添加了按钮)。我尝试隐藏playerLayer
,但按钮仍然没有显示在下面,因此似乎按钮甚至不在视图层次结构中。 最佳答案
也许这可以帮助
let player = AVPlayer(url: videoURL!)
let playerLayer = AVPlayerLayer(player: player)
let btn = UIButton()
btn.frame = CGRect(x: 23, y: 34, width: 25, height: 30)
playerLayer.addSublayer(btn.layer)
self.view.layer.addSublayer(playerLayer)