2012-10-22 44 views
6

我的應用支持的界面方向爲肖像和顛倒。但是,當播放視頻時,我希望它播放全屏風景。目前使用此代碼,它只能播放肖像,即使設備旋轉:如何在僅肖像應用中使用MPMovieViewController播放風景視頻

[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen]; 
player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
[self presentMoviePlayerViewControllerAnimated:player]; 

我怎麼能強迫它進入橫向模式?

+0

對於iOS6的,這個答案是更好: http://stackoverflow.com/questions/12577879/shouldautorotatetointerfaceorientation-is-not-working-in-ios-6 – fpauer

回答

11

這是我如何做到這一點:
在項目文件,請確保您正在支持橫向模式 supported interface orientations
現在所有的ViewControllers應該還是人像只有中添加以下代碼

//ios6 
- (BOOL)shouldAutorotate { 
    return NO; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; 
} 
- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

//ios4 and ios5 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

我已經把iOS5和iOS6調用放在一起,這樣我的代碼就可以同時運行了。

當你的MPMoviePlayerController視圖變成全屏時,它將成爲一個新的ViewController,它被分層放置在其他所有東西之上。因此,它將被允許根據項目支持的界面方向進行旋轉。它不會看到你將其他ViewController強制爲Portrait的位置。

+1

,謝謝,我會,如果我再打這個不得不,但我希望有一種方法可以做到這一點,而不必在每個視圖控制器中放置該方向代碼(有很多)。 – soleil

+0

我所做的是創建一個UIViewController,它只包含這些方法。然後,我讓所有需要成爲肖像的UIViewController都從此繼承,而不是繼承自UIViewController。在'.h'文件的'@ interface'一行中,我將MyPortraitViewController的名稱放在UIViewController的位置。 – Walter

+0

@soleil,根據我的理解,這是唯一的方法,不幸的是......爲什麼在Apple支持的界面上的UIViewController文檔中的原因是**系統與視圖控制器支持的方向相交與應用程序的支持的方向(由Info.plist文件或應用程序委託的應用程序:supportedInterfaceOrientationsForWindow:方法確定)來確定是否旋轉。' –

相關問題