0
所以在我的應用程序中有一個MPMoviePlayerViewController
它允許用戶查看視頻。他們能夠以任何方向在MPMoviePlayerViewController
中觀看視頻,並且一旦完成並點擊「完成」,它們將返回到先前的視圖控制器,但僅以縱向顯示。問題是,當按下「完成」按鈕時,視圖控制器會短暫地在風景中閃爍,然後像應該那樣返回到肖像。這是它看起來運行時,這樣的:http://1drv.ms/1RSqUUDMovieViewController的奇怪的方向行爲
我的代碼附:
import UIKit
import MediaPlayer
class VideoViewController: UIViewController {
var movieViewController : MPMoviePlayerViewController?
var movieplayer : MPMoviePlayerController!
override func viewDidLoad() {
var url = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
movieViewController = MPMoviePlayerViewController(contentURL: url)
}
override func viewWillAppear(animated: Bool) {
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
@IBAction func WatchPressed(sender: AnyObject)
{
self.presentMoviePlayerViewControllerAnimated(movieViewController)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "Rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
func Rotated()
{
if UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)
{
if UIDevice.currentDevice().orientation.rawValue == 4 || UIDevice.currentDevice().orientation.rawValue == 3
{
movieViewController!.view.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
}
}
else if UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)
{
if UIDevice.currentDevice().orientation.rawValue == 1 || UIDevice.currentDevice().orientation.rawValue == 2
{
movieViewController!.view.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
編輯
當使用此代碼:(正如下面的建議) http://txt.do/nt1s 的用戶當他們旋轉到橫向時拋出電影播放器,並且在旋轉到縱向之前,他們仍然短暫地看到先前的視圖控制器處於橫向。
我剛剛嘗試過,但每當我嘗試觀看風景中的視頻時,用戶都將從視頻播放器中移除,並在旋轉至肖像之前在風景中顯示視圖控制器... @Dharmesh_Khani – dwinnbrown
我應該替換名爲「旋轉「與你的功能?我的代碼在這裏:http://txt.do/nt1s – dwinnbrown
這是完整的代碼:http://pastebin.com/VLkdmXjx –