2014-02-24 96 views
2

在您將這個問題投下來之前,請注意,我已經嘗試在stackoverflow上實現所有可用的解決方案。這是問題:解僱MPMoviePlayerViewController後自動旋轉ViewController

我的應用程序只能在肖像模式下運行。視頻播放器是唯一需要處於風景中的東西。當用戶點擊我的TableViewCell這段代碼被稱爲:

MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl]; 
    [self presentMoviePlayerViewControllerAnimated:moviePlayer]; 

在那之後,我需要給用戶觀看視頻無論在縱向和橫向模式的能力。完成後,所有內容都應回到縱向模式。我試圖調用的代碼塊在我AppDelegate.m

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait; 

    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) { 
     orientations = UIInterfaceOrientationMaskAllButUpsideDown; 
    } 

    return orientations; 
} 

有了它,一切都很好,除了一兩件事 - 當影片結束時,或者當用戶點擊「完成」按鈕,而在橫向模式,我的視圖控制器也出現在橫向模式。

除此之外,我嘗試了很多其他方法 - 但似乎沒有任何工作。

我會很高興的任何幫助!

+0

請參閱http://stackoverflow.com/questions/21911151 - 這似乎是'MPMoviePlayerController'實現中的一個錯誤。 – Till

回答

1

謝謝@Shubham - Systematix的the answer

所有我要做的就是去除AppDelegate每一個相關的自轉,除了這個方法代碼:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    if ([[window.rootViewController presentedViewController] isKindOfClass:  [MPMoviePlayerViewController class]]) 
    { 
     //NSLog(@"in if part"); 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
    } 
    else 
    { 
     //NSLog(@"in else part"); 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 

當我做的一切工作就像一個神奇!

相關問題