2014-04-03 27 views
3

我有一個應用程序需要在整個時間都處於肖像模式,除非播放視頻。爲了在我的項目設置中啓用VideoController的橫向模式,我啓用了所有支持的方向模式。 然而這允許我的其他控制器也可以旋轉。爲了解決這個問題,我添加以下到我的根UINavigationControlleriOS狀態欄忽略根控制器中的supportedInterfaceOrientations

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    if([[VideoPlaybackManager sharedManager] videoIsPlaying]) { 
     return UIInterfaceOrientationMaskLandscape; 
    } 

    return UIInterfaceOrientationMaskPortrait; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    if([[VideoPlaybackManager sharedManager] videoIsPlaying]) { 
     return UIInterfaceOrientationLandscapeLeft; 
    } 
    return UIInterfaceOrientationPortrait; 
} 

現在我有兩個問題:

  1. 應用程序的標準屏幕尊重限制,並留在縱向方向。但是,狀態欄會更改方向,而不會中斷用戶界面。如果設備處於橫向模式,我會在縱向屏幕上顯示橫向狀態欄。我該如何解決這個問題,使狀態欄保持原狀?

  2. 我爲視頻播放時設置了首選的橫向方向。這不起作用,並且preferredInterfaceOrientationForPresentation似乎根本不被調用。我做錯了什麼,或者我錯過了什麼?

UPDATE 我通過添加固定1.下面我AppDelegate:然而

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    if([[VideoPlaybackManager sharedManager] videoIsPlaying]) { 
     return UIInterfaceOrientationMaskAll; 
    } 

    return UIInterfaceOrientationMaskPortrait; 
} 

問題號2仍然存在。當我開始播放視頻時,它不是從橫向開始的。任何想法?

任何幫助將不勝感激! 謝謝!

+0

你嘗試從'shouldAutorotate'返回'NO'影片時不打,堅持你的狀態欄方向是什麼? – ismailgulek

+1

我剛剛嘗試過,狀態欄似乎沒有受到它的影響 - 它再次改變方向。 – planewalker

回答

0

這段代碼在AppDelegate.m將有助於

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    UIViewController *topScreen = self.window.rootViewController; 
    while (topScreen.presentedViewController) { 
     topScreen = topScreen.presentedViewController; 
    } 
    return topScreen.supportedInterfaceOrientations; 
}