AVPlayerLayer在UIView图层中的位置 [英] AVPlayerLayer Position in UIView Layer

查看:102
本文介绍了AVPlayerLayer在UIView图层中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift编写一个应用程序,以通过HLS查看监视摄像机.我有基本的设备列表,并且可以选择实时视图并显示流,但是,我需要移动AVPlayerLayer,但很难弄清楚这一点.这是我当前的代码:

I am writing an application using Swift to view surveillance cameras via HLS. I have the basic device list working and I am able to segue to the Live view and display the stream however, I need to move the AVPlayerLayer and I am having trouble figuring this out. Here is my current code:

    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点,因为我为每个视图场景都有一个标题.

I want the AVPlayerLayer to be placed 50 points below the top because I have a header for each view scene.

谢谢!

推荐答案

因此,您无法在视图中的特定位置放置子层.解决方法如下:

So it just so happens that you cannot place a sub layer in a view in a specific position. Here is the solution:

    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()

我必须设置播放器的特定高度,然后设置位置.

I had to set a specific height of the player and then the position.

这篇关于AVPlayerLayer在UIView图层中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆