2012-04-21 2 views
0

나는 가로 모드에서 세 개의 탭 내 탭 표시 줄 응용 프로그램을 원하지만, portrait.I에 있어야합니다 세 번째 탭은스토리 보드 탭 바 컨트롤러 뷰 방향 풍경/potrait의

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 
를 사용하여 가로로 전체 응용 프로그램을 변환 결국 모든보기 컨트롤러에서

탭 막대 응용 프로그램으로 모든 하위보기 컨트롤러가이를 가로로 표시해야합니다.

내 .plist 파일에는 먼저 Lanscape 옵션이 포함 된 다음 세로가 추가되었습니다.

세로로 세 번째 탭을 회전하려면 어떻게해야합니까?

귀하의 도움에 감사드립니다.

답변

2

슬프게도 UITabBarController는 회전 요구 사항이 다른보기 컨트롤러를 잘 처리하지 못합니다. 이것을 처리하는 가장 좋은 방법은 UITabBarController를 서브 클래스 화하고 shouldAutorotate에서 단순히 화면상의 뷰 컨트롤러로 요청을 전달하는 것입니다. 코드는 다음과 같습니다

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Let's grab an array of all of the child view controllers of this tab bar controller 
NSArray *childVCArray = self.viewControllers; 

// We know that at 5 or more tabs, we get a "More" tab for free, which contains, assumingly, 
// a more navigation controller 

if (self.selectedIndex <= 3) { 
    UINavigationController *navController = [childVCArray objectAtIndex:self.selectedIndex]; 

    // We're in one of the first four tabs, which we know have a top view controller of UIViewController 
    UIViewController *viewController = navController.topViewController; 

    return [viewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 
else { 
    // This will give us a More Navigation Controller 

    UIViewController *viewController = [childVCArray objectAtIndex:self.selectedIndex]; 

    return [viewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 

return NO; 
} 

이것은 당신이 5+보기 컨트롤러 탭 표시 줄의 더 탐색 컨트롤러를 사용하고 스스로 자신의 UINavigationController가에없는 걸 가정합니다. 만약 그렇다면,이 코드를 적합하게 바꾸는 것은 사소할 것입니다.

이 방법을 복사하거나 그냥 내가 세 개의 탭이 그것을 .Edited tabbarcontroller에 대한 귀하의 파일을 추가 here

+0

에서 .H /하는 .m 파일을 잡을 수 있도록 내가, 내 GitHub의에서이 서브 클래스 최대를 기록했다. if (self.selectedIndex <= 2) else case를 "more"로 제거했습니다. 세 번째보기 컨트롤러에서 세로로만 표시하려면 (interfaceOrientation == UIInterfaceOrientationPortrait)에 대해 YES를 리턴하십시오. in autorotate 메소드가 필요합니다. 하지만 아직은 prtrait로 회전하지 않습니다. 내가 틀린 점은 무엇입니까? – Senorina

+0

selectedIndex는 0에서 시작하므로 3 개의 탭이 0, 1 및 2 인 경우 UINavigationControllers에있는보기 컨트롤러입니까? 코드를 살펴보면 탭 막대의보기 컨트롤러가 탐색 컨트롤러라고 가정하고 그 탭 컨트롤러를 가져옵니다. 만약 당신이보기 컨트롤러가 있다면, nav 컨트롤러에 내용을 입력하십시오. – jmstone617

+1

답장을 보내 주셔서 감사합니다. jmstone .. 세번째 뷰는 네비게이션 컨트롤러에 없습니다. 그래서 방금 UIViewController *를 추가했습니다. viewController = [childVCArray objectAtIndex : self.selectedIndex]; for selectedIndex == 2 기기 방향을 세로로 변경하면보기가 세로로 회전합니다. 그런 다음 다른 모든 탭이 세로로 표시됩니다. 세 번째보기가 선택 될 때마다 세로 방향으로 강제 표시되도록하려고합니다 (장치의 방향이 바뀌는 경우뿐만 아니라). 다른 탭은 항상 가로로 유지되어야합니다. 제안 사항이 있습니까? – Senorina

관련 문제