【问题标题】:How do I rotate MPMoviePlayer as the movie is playing in iOS 8 with Swift?如何在使用 Swift 在 iOS 8 中播放电影时旋转 MPMoviePlayer?
【发布时间】:2015-05-14 12:11:48
【问题描述】:
我想提出并回答我自己的问题,以防其他人觉得它有帮助。
moviePlayer 将开始按预期正常播放
moviePlayer.view.frame = self.view.bounds
但是,当在电影中间旋转时,tabBar 会旋转,但moviePlayer 不会。这将裁剪电影屏幕的一部分,或者它不会像最初预期的那样改变为填充整个屏幕。
【问题讨论】:
标签:
swift
ios8
orientation
mpmovieplayercontroller
【解决方案1】:
在 func viewDidLoad() 中添加这个通知服务:
NSNotificationCenter.defaultCenter() .addObserver(self, selector: "movieOrientationChanged", name: UIDeviceOrientationDidChangeNotification, object: nil)
下面是响应该通知的方法(moviePlayer 是 MPMoviePlayerController 类型的类变量):
func movieOrientationChanged() {
moviePlayer!.view.frame = self.view.bounds
}
【解决方案2】:
对于 swift 4,在 viewDidLoad 中添加此代码
NotificationCenter.default .addObserver(self, selector: #selector(VideoViewViewController.movieOrientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)