尝试将视频放置在导航栏下方。适用于人像和风景。可能吗?

Background video move to under navigation

这是我正在使用的以下代码

override func viewDidLoad()
{
    super.viewDidLoad()
    addNavBarImage()

    let URL = Bundle.main.url(forResource: "homedocapp", withExtension: "mp4")

    Player = AVPlayer.init(url: URL!)

    PlayerLayer = AVPlayerLayer(player: Player)
    PlayerLayer.videoGravity = AVLayerVideoGravityResizeAspect
    PlayerLayer.frame = view.layer.bounds

    Player.actionAtItemEnd = AVPlayerActionAtItemEnd.none


    Player.play()

    view.layer.insertSublayer(PlayerLayer, at: 0)

    NotificationCenter.default.addObserver(self, selector: #selector(playerItemReachEnd(notification:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: Player.currentItem)


先感谢您

最佳答案

使用情节提要时,可以将其顶部视图的顶部空间约束设置为0:
ios - 快速将背景视频移到导航栏下-LMLPHP

如果您坚持要通过代码来实现,那么我建议您使用可可豆荚:PureLayout在'viewDidLayoutSubviews'方法中设置自动布局。

迅捷3

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    player.autoPinEdge(toSuperviewEdge: .top)
}

关于ios - 快速将背景视频移到导航栏下,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45333718/

10-13 03:40