2010-10-18 116 views
24

從iOS 3.2開始,MPMoviePlayerController類允許在視圖層次結構中嵌入電影。 現在我遇到了這個問題:我通過放置MPMoviePlayerController的一個實例來創建我的肖像視圖。當用戶觸摸「全屏」按鈕時,該視圖進入全屏模式,但視圖保持縱向。當用戶旋轉設備時,全屏電影視圖不會自動旋轉,因爲我的應用禁止橫向界面方向。 因此,爲了允許電影播放器​​全屏視圖的自動旋轉,我改變了我的視圖控制器shouldAutorotateToInterfaceOrientation:如果 - 且僅當 - 如果 - 電影播放器​​處於全屏模式時才返回YES風景。 這很好地工作:當用戶進入全屏,然後旋轉到風景時,播放器會自動旋轉到橫向並填充整個屏幕。MPMoviePlayerController重定向肖像到風景並返回到肖像(iOS 4.1)

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    //return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) { 
     return(YES); 
    } 

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) { 
     return([movieController isFullscreen]); 
    } 

return(NO); 
} 

現在問題出現時,當我在全屏視圖中觸摸「完成」按鈕,同時保持在橫向。全屏關閉,然後我看到的是我的原始視圖自動旋轉:但我不希望這種自動旋轉。

的部分,但不能接受的解決辦法,就是要聽「MPMoviePlayerDidExitFullscreenNotification」,如果接口旋轉爲橫向,力重新定向到使用無證和私有函數:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait] 

該作品但由於禁止使用此方法,因此不可接受。

我試圖強制使用[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]的方向,但因爲我在選項卡欄中這不起作用(UITabBar保持橫向大小)。

感謝您的幫助

+0

您是否找到解決方案?我處於相同的情況,我找不到解決方案。 – klefevre 2013-04-18 09:08:03

+0

理論上用iOS6引入的新方法來管理定位,這個問題可以通過直接設置每個視圖控制器方向來解決。這可以通過使用向每個視圖控制器請求方向權限的新方法來完成。 – viggio24 2013-04-18 13:08:34

回答

2

您可以爲MPMovieplayer使用單獨的視圖控制器。你不必重寫

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在原來的視圖控制器。

如果您使用的是MPMoviePlayerViewController,則所有設置都已正確設置,因爲默認情況下,方法shouldAutorotateToInterfaceOrientation:將返回YES。你可以使用它作爲一個子視圖或致電
presentMoviePlayerViewControllerAnimated: