2017-07-26 5 views
0

NavBarの下にビデオを収めようとしています。ポートレートとランドスケープの両方のために。出来ますか?ここでNavagationBarの下の背景ビデオの移動を速く

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) 

を使用して、次のコードL'mはストーリーボードを使用する場合は、あなたが0にそのスーパーにトップスペースの制約を設定することができ、事前

+0

:view.bounds.origin.xを、y:view.bounds.origin.y + 44、width:view.bounds.size.width、height:view.bounds.size.height - 44) '' //ナビゲーションの高さを仮定すると= 44' – Santosh

+0

ありがとうそれを試してください。 – o2webdev

答えて

0

にありがとうです。 enter image description here

コードで行うことを強くお勧めする場合は、ココアポッド:0123を使用することをおすすめします。を使用して、 'viewDidLayoutSubviews'メソッドで自動レイアウトを設定します。

スウィフト、あなたの `navigation's`高さに応じて` frame`を設定できないのはなぜ?: `PlayerLayer.frame = CGRect(×3

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

ありがとうLloyd – o2webdev

+0

@ o2webdev問題ありません!ナビゲーションバーの下に表示する場合は、player.frame.origin.yを0に設定することもできます。それが役に立てば幸い。 –

関連する問題