在AVPlayerLayer - iOS Swift顶部添加按钮

时间:2017-10-04 14:27:25

标签: button avplayer avplayerlayer

我试图在我的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并且按钮仍然没有显示在下方,所以按钮似乎甚至不在视图层次结构中。

1 个答案:

答案 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)