我试图在我的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
并且按钮仍然没有显示在下方,所以按钮似乎甚至不在视图层次结构中。
答案 0 :(得分:0)
也许这可以帮助
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)