【问题标题】:Add button on top of AVPlayerLayer - iOS Swift在 AVPlayerLayer 顶部添加按钮 - iOS Swift
【发布时间】:2017-10-04 14:27:24
【问题描述】:

我正在尝试在我的AVPlayerLayer 顶部添加一个播放按钮,但它没有显示出来。

我有一个名为 playerViewUIView 作为 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,但该按钮仍然没有显示在下方,因此该按钮似乎甚至不在视图层次结构中。

【问题讨论】:

    标签: button avplayer avplayerlayer


    【解决方案1】:

    也许这会有所帮助

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 2014-03-05
      • 2019-04-22
      • 1970-01-01
      • 2019-11-08
      相关资源
      最近更新 更多