当电影在iOS 8中使用Swift播放时,如何旋转MPMoviePlayer?

时间:2015-05-14 12:11:48

标签: swift ios8 orientation mpmovieplayercontroller

我想问及回答我自己的问题,万一其他人会发现它有用。

使用

,moviePlayer将按照预期开始播放
moviePlayer.view.frame = self.view.bounds

但是,在电影中期旋转时,tabBar会旋转,但不会旋转moviePlayer。这将裁剪电影屏幕的一部分,或者它不会像原先预期的那样改变以填满整个屏幕。

Changing rotation of portrait to landscape crops the mpmovieplayer

2 个答案:

答案 0 :(得分:4)

在func viewDidLoad()中添加此通知服务:

NSNotificationCenter.defaultCenter() .addObserver(self, selector: "movieOrientationChanged", name: UIDeviceOrientationDidChangeNotification, object: nil)

和,这里的方法(moviePlayer是MPMoviePlayerController类型的类变量)响应该通知:

func movieOrientationChanged() {
     moviePlayer!.view.frame = self.view.bounds 
}

答案 1 :(得分:1)

for swift 4在viewDidLoad

中添加此代码
NotificationCenter.default .addObserver(self, selector: #selector(VideoViewViewController.movieOrientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)