2014-09-03 15 views
0

我使用xcdYoutubeVideoViewController從MPMoviePlayerController的子類。我的申請是肖像。要啓動movieplayer,我這樣做:如何只旋轉subclassed mpmovieplayer控制器,並保持其他視圖固定到肖像

UINavigationController *navBarController = (UINavigationController*)[[[UIApplication sharedApplication] keyWindow] rootViewController] ; 
[navBarController presentMoviePlayerViewControllerAnimated:vc]; 

其中,Vc是XCDYouTubeVideoPlayerViewController的實例。我怎樣才能允許旋轉只在這個視圖和按下完成按鈕在movieplayer把應用程序回到肖像?

+0

可能重複檢查這個http://stackoverflow.com/questions/19768620/ios-7-restrict-landscape-orientation-only-in-one-view-controller – Rajesh 2014-09-03 06:58:42

+0

是,它的導航控制器。我這樣做:UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:btVC]; self.window.rootViewController = navController;其中btVC是從UIViewController的子類別 – 2014-09-03 07:14:58

回答

2

您應該在每個視圖控制器中覆蓋:-(BOOL) shouldAutorotate。如果您希望該視圖控制器以其他方式旋轉NO,則返回YES。一定要檢查故事板設置中支持的方向。

更新:在你父控制器呈現玩家嘗試這個辦法:

- (BOOL)shouldAutorotate 
{ 
    // 1. check if the parent presentedViewController is the nav containing the player 

    // 2. if yes, return YES, NO otherwise 
} 

如果應用程序根控制器導航控制器,子類UINavigationViewController和使用該類創建的應用程序根視圖控制器應用代理

@implementation ANavigationViewControllerSubClass 


- (BOOL)shouldAutorotate 
{ 
    return [self.topViewController shouldAutorotate]; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [self.topViewController preferredInterfaceOrientationForPresentation]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [self.topViewController preferredInterfaceOrientationForPresentation]; 
} 
+0

重寫shouldAutorotate沒有幫助。我需要在哪裏使用preferredInterfaceOrientationForPresentation?它應該在父視圖還是電影播放器​​中? – 2014-09-03 07:05:05

+0

問題:什麼是應用程序的根控制器,它是UINavigationView控制器嗎? – Hokage 2014-09-03 07:14:21

+0

是的,它的導航控制器。我這樣做:UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:btVC]; self.window.rootViewController = navController;其中btVC從UIViewController的子類別 – 2014-09-03 07:15:47

相關問題