2017-07-29 105 views
0

添加滾動型我對Main.storyboard頂部的視頻幀,我把滾動型用的TextView下的是,我現在的問題是滾動型是不是在所有設備上的同一位置。下的視頻幀

例如,在iPhone 7加上它在正確的位置,但在iPhone SE的不同一樣的iPad。

這裏是我的ViewController.swift代碼:

import UIKit 
import AVFoundation 
import AVKit 

class ViewController: UIViewController { 

    let playerController = AVPlayerViewController() 
    var player:AVPlayer? 

    @IBOutlet weak var textView: UITextView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let videoString:String? = Bundle.main.path(forResource: "m9", ofType: ".mov") 

     playerController.player = player 
     self.addChildViewController(playerController) 
     let screenSize = UIScreen.main.bounds.size 
     let videoFrame = CGRect(x: 0, y: 30, width: screenSize.width, height: (screenSize.width * 9)/16) 
     playerController.view.frame = videoFrame 
     self.view.addSubview(playerController.view) 
     player?.play() 

然後我試圖了滾動鏈接到視頻幀:

let frame1 = CGRect(x: 0, y: 350 + videoFrame.height , width: screenSize.width, height: screenSize.height) 

textView.frame = frame1 
+0

爲什麼空行和物品,無關你的問題? –

回答

0

只是讓你滾動型的出口,並設置其框架,如:

let scrollViewFrame= CGRect(x: 0, y: playerController.view.frame.maxY, width: screenSize.width, height: replace_actual_height) 
scrollView.frame = scrollViewFrame 

然而,最好是使用自動佈局爲,而不是設置框架。鏈接在這裏。

Understanding Autolayout

+0

非常感謝你很多人 – Babak

0

此代碼工作完全在滾動視圖。簡單滾動視圖中添加avplayerviewcontoller那就不要刷所以將這段代碼...

let url = // whatever 
let player = AVPlayer(URL:url) 
let av = AVPlayerViewController() 
av.player = player 
av.view.frame = // whatever 
self.addChildViewController(av) 
self.view.addSubview(av.view) 
av.didMoveToParentViewController(self) 

代碼爲HERE

+0

非常感謝 – Babak