Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button 在AVPlayerLayer顶部添加按钮-iOS Swift_Button_Avplayer_Avplayerlayer - Fatal编程技术网

Button 在AVPlayerLayer顶部添加按钮-iOS Swift

Button 在AVPlayerLayer顶部添加按钮-iOS Swift,button,avplayer,avplayerlayer,Button,Avplayer,Avplayerlayer,我试图在我的AVPlayerLayer上添加一个播放按钮,但它没有显示出来 我有一个名为playerView的ui视图作为IBOutlet 下面是我如何创建player和相应的playerLayer,并将其放入playerView: player = AVPlayer() superLayer = self.playerView.layer playerLayer = AVPlayerLayer(player: player) playerLayer.frame

我试图在我的
AVPlayerLayer
上添加一个播放按钮,但它没有显示出来

我有一个名为
playerView
ui视图作为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)
问题是
playerLayer
上的
playevideobutton
并没有显示(该按钮添加在情节提要中)。我试图隐藏
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)