我有一个嵌入AVPlayer的UIview。现在,当我播放它时,它似乎并不能覆盖整个UIview。下面是代码:

@IBOutlet weak var introVideo: UIView!

var player: AVPlayer!

func playIntro() {

    if let moviePath = Bundle.main.path(forResource: "intro", ofType: "mp4") {
        let movieURL = URL(fileURLWithPath: moviePath)
        player = AVPlayer(url: movieURL)
        let playerLayer = AVPlayerLayer()
        playerLayer.player = player
        playerLayer.frame = introVideo.bounds
        playerLayer.backgroundColor = UIColor.clear.cgColor
        player.actionAtItemEnd = .none
        playerLayer.videoGravity = AVLayerVideoGravityResizeAspect
        introVideo.layer.addSublayer(playerLayer)
        player.play()
        NotificationCenter.default.addObserver(self,
                                               selector: #selector(playerItemDidReachEnd(notification:)),
                                               name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
                                               object: player.currentItem)        }
}


看起来像这样:

ios - 调整播放器窗口的大小-LMLPHP

我该如何解决

最佳答案

我解决了我在viewDidLoad()中调用此函数,但是它在每次加载时都以某种方式更新了视图。因此,因此,应该在viewDidLayoutSubviews()中更新边界

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    playIntro()
}

关于ios - 调整播放器窗口的大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47085626/

10-14 20:46
查看更多