【发布时间】:2017-11-02 22:29:53
【问题描述】:
我有一个嵌入 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) }
}
看起来像这样:
我该如何解决这个问题
【问题讨论】:
-
尝试使用
AVLayerVideoGravityResizeAspectFill而不是AVLayerVideoGravityResizeAspect -
试过了。没有运气
-
留下一个拒绝投票的理由是有道理的,否则这是一个愚蠢的举动