我正在编写一个使用Swift通过HLS查看监控摄像头的应用程序。我有基本的设备列表工作,我能够segue到实时视图并显示流,但是,我需要移动AVPlayerLayer,我有麻烦弄清楚这一点。下面是我当前的代码:
let player = AVPlayer(URL: url!)
let playerLayer = AVPlayerLayer(player: player)
let view = UIView(frame: CGRectMake(0, 0, screenSize.width, screenSize.height))
self.view.layer.borderWidth = 1
self.view.layer.borderColor = UIColor(red:222/255.0, green:225/255.0, blue:227/255.0, alpha: 1.0).CGColor
self.view.layer.addSublayer(playerLayer)
playerLayer.frame = view.bounds
player.play()
我想把AVPlayerLayer放置在顶部以下50点,因为我有一个头为每个视图场景。
谢谢!
所以你不能在视图的特定位置放置子图层。解决方案如下:
let player = AVPlayer(URL: url!)
let playerController = AVPlayerViewController()
playerController.player = player
playerController.view.frame = CGRectMake(0, 50, screenSize.width, 240)
self.view.addSubview(playerController.view)
self.addChildViewController(playerController)
player.play()
我必须设置玩家的特定高度,然后是位置
我不知道你在哪里将PlayerLayer与视图和/或将其添加为子视图/图层到任何东西?您需要将其添加为子层。
let player = AVPlayer(URL: url!)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = CGRectMake(0,50,screenSize.width, screenSize.height)
self.view.layer.addSublayer(playerLayer)
player.play()
我按照你在问题中建议的那样将Y位置移动了50。