1

이 문제를 이해하기 위해 빨간색 배경과 단추가있는 간단한 응용 프로그램을 만들었습니다. 이 앱은 가로 모드이며 iOS6 프레임 워크로 제작됩니다. (BOOL) shouldAutorotate과 - - 뷰 컨트롤러 (NSUInteger) supportedInterfaceOrientations하고 시작 내가 방법을 넣으면 가로 (오른쪽 홈 버튼)ios 6.0 - Landscape not working - subclassed UINavigationController는 shouldAutorotate 메서드를 호출하지 않습니다.

:

난 단지가에 지원되는 인터페이스 방향의 PLIST 속성을 설정 한 UINavigationController를 사용하지 않고 Windows의 rootViewController로 가로 방향으로 이동합니다.

아래 예와 같이 서브 클래 싱 된 UINavigationController를 사용하고 - (BOOL) shouldAutorotate 및 - (NSUInteger) supportedInterfaceOrientations를 구현하면 가로 방향이 달성되지 않고 - (BOOL) shouldAutorotate가 호출되지 않습니다.

내 서브 클래 싱은 UINavigationController에 다음 코드를했다 : 나는이 방법을 내 AppDelegate에에서

//For iOS 5.x and below 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationLandscapeRight); 
} 

//For iOS 6.0 
-(NSUInteger)supportedInterfaceOrientations 
{ 
return UIInterfaceOrientationMaskLandscapeRight; 
} 

-(BOOL)shouldAutorotate 
{ 
return YES; 
} 

이 : 내가 구현하지만 발견 비슷한 질문에 수많은 답변을 보았다

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 



self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
// Override point for customization after application launch. 
self.window.backgroundColor = [UIColor whiteColor]; 

viewController = [[MDViewController alloc] init]; //a very simple viewcontroller containing button on red background which should be in landscape mode 
navigationController = [[MDNavigationController alloc] initWithRootViewController:viewController]; 
[self.window setRootViewController:navigationController.topViewController]; 

[self.window makeKeyAndVisible]; 
return YES; 
} 

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow: (UIWindow *)window { 
    return UIInterfaceOrientationMaskLandscapeRight; 
} 

을 그 그들은 일을 실패합니다. 감사합니다. .

답변

2

당신은이 일을 안 :

[self.window의 setRootViewController :있는 navigationController]

대신 :

[self.window의 setRootViewController : navigationController.topViewController];

+1

예프. 그것이 바로 내가해야만했던 일입니다. 감사 :) – Zigglzworth