gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:02:07 24 4
gpt4 key购买 nike

我有一个 UIview,我在其中嵌入了一个 AVPlayer。现在当我玩它时,它似乎没有覆盖整个 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) }
}

它看起来像这样:

enter image description here

如何解决这个问题

最佳答案

我解决了。我在 viewDidLoad() 中调用这个函数,但它在每次加载时都会以某种方式更新 View 。因此,出于这个原因,应该在 viewDidLayoutSubviews()

中更新边界
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
playIntro()
}

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com