2014-05-19 2 views
0

안녕하세요 저는 iOS 7을 사용하여 iPhone 개발을 처음 접했습니다. 기본적으로 내 응용 프로그램이 화면 회전 (즉, 화면 방향 변경)에 응답하기를 원합니다. 내 프로젝트는 UITabBarControllerUINavigationController을 모두 사용합니다. 그러나 기기를 회전 시키면 ViewControllerLoginView.m에 "shouldAutorotate"기능이 호출되지 않습니다.UITabBarController 및 UINavigationController 서브 클래 싱

따라서 답변은 here에 있으며 그 부분이 UITabBarControllerUINavigationController 인 하위 지점까지 답변을 따라 왔습니다. 어떤 사람이 내게 방향성 동작을 LoginView.m 클래스 내에서 또는 전체 프로젝트에 추가 (즉, 참조)하는 방법을 설명 할 수 있습니까?

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

주셔서 감사 서브 클래스 UITabBarController가에서

+0

누구나? 제발 도와주세요 .. – Yrol

+0

좀 더 자세히하려고 노력하고 있습니다. 귀하의 경우에는 TabBarController 또는 NavigationController 인 루트 뷰 컨트롤러에 대해 shouldAutorotate가 호출되지만 원하는 결과에 대한 자세한 내용이 필요합니다. – Argent

+0

@Argent 기본적으로 화면 방향을 변경하려고합니다. 화면 회전. "UIViewController"를 확장 한 LoginView.m이라는 뷰가 있습니다. 또한 내 AppDelegate.m UITabBarController 및 UINavigationController 속성을 참조하십시오. 보기가 자동 회전되도록하고 기본으로 사용할 수있는 기본 iOS 컨트롤을 사용하려면 – Yrol

답변

0

을 각각 viewcontrollers에서

- (BOOL)shouldAutorotate { 

    UINavigationController *navView = (UINavigationController *)[self selectedViewController]; 
    //Get the selected current tab viewcontroller. I guess you are having a Navigationcontroller  

    UIViewController *vc = [navView.viewControllers objectAtIndex:0]; 
    //Fetch root viewcontroller of your navigationcontroller 

    return [self checkOrientationForViewController:vc]; 

} 

-(BOOL) checkForViewsForViewController : (UIViewController *)vc{ 

    if([vc isKindOfClass:[FirstViewController class]]){ 

     FirstViewController *vc1 = (FirstViewController *)vc; 

     return [vc1 shouldAutorotate]; 
    } 
    if([vc isKindOfClass:[SecondViewController class]]){ 

     SecondViewController *vc2 = (SecondViewController *)vc; 

     return [vc2 shouldAutorotate]; 
    } 
    if([vc isKindOfClass:[ThirdViewController class]]){ 

     ThirdViewController *vc3 = (ThirdViewController *)vc; 

     return [vc3 shouldAutorotate]; 
    } 
    return YES; 
} 

가 shouldAutorotate 방법 대신 서브 클래스의

+0

시간 내 주셔서 감사합니다.AppDelegate 파일에서이를 참조해야 응용 프로그램에 이러한 사용자 지정 클래스를 사용하고 있음을 알릴 수 있습니까? – Yrol

+0

네, 가져와야합니다. AppDelegate – iPrabu

+0

어떻게 할 수 있는지 말해 주시겠습니까? 그것이 혼란 스럽습니다. 다시 한 번 감사드립니다 – Yrol

0

를 구현하고, 또한은 UINavigationController 및 UITabBarController가 메소드를,이 위임되어 있음을 알고 가치가있다 런타임에서 회전을 처리하게합니다.

- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController 
- (NSUInteger)tabBarControllerSupportedInterfaceOrientations:(UITabBarController *)tabBarController 

Ref doc

Ref doc.

. 애플이 위임을 사용하는

+0

고마워, 나는 그것을 줄 것이다 .. – Yrol

0

대신 시간이 지남에 가장 신뢰할 수있는 솔루션이 될 것입니다 위임을 사용하여 탐색 및 TabBar의 컨트롤러를 서브 클래 싱하지 않는 수있는 조언을 제거 할 경우

Evenf 당신은 또한

- (NSUInteger)supportedInterfaceOrientations 

은 UINavigationController를 사용할 수 있습니다 UITabBarController는 하위 뷰 컨트롤러에게 그들이 지원하는 인터페이스 방향을 요청합니다. 따라서 LoginView.m에 "- (NSUInteger) supportedInterfaceOrientations"를 구현하고 적절한 인터페이스 방향을 반환 할 수 있습니다.

또한 Info.plist를 편집하고 지원되는 인터페이스 방향을 추가해야합니다. 프로젝트보기를 열어 Xcode로이 작업을 수행 할 수 있습니다. 또한보십시오 Apples documentation on supporting interface orientations

+0

고마워, 나는 그것을 시도 할 ..] – Yrol