2016-09-05 4 views
5

가로 모드에서 1 개 또는 2 개의 UIViewcontroller를 표시하고 다른 모드에서는 세로로 표시하려고합니다. 이 목적을 위해 AppDelegate에서이 함수를 구현했습니다. 내가 가로 방향이 필요 UIViewController에 (들)에서iOS9 supportedInterfaceOrientationsForWindow 호출이 중지됩니다.

@property (nonatomic, assign) UIInterfaceOrientationMask orientation; 

: AppDelegate.h에, 방향이

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    return self.orientation; 
} 

. 나는이 코드를

-(void)viewWillAppear:(BOOL)animated 
{ 
    self.appDelegate.orientation = UIInterfaceOrientationMaskLandscape; 
} 

-(void)viewWillDisappear:(BOOL)animated 
{ 
    self.appDelegate.orientation = UIInterfaceOrientationMaskPortrait; 
} 

그러나, 나는 'LandscapeViewController'이 확인 작동에 갈 때, 나는 돌아가고, 그것은, 내가 다시 그 확인 '을 LandscapeViewController'에 가서 작품을 좋아

를 배치 그리고 나서 돌아 왔을 때, supportedInterfaceOrientationsForWindow 메소드가 호출되는 것을 멈 춥니 다. 그 이유가 뭐야? 아니면 내가 이상한 일을하고있는거야?

답변

3

당신이 UITabBarController가이 UITabBarController가에 대한 사용자 정의 클래스를 만들고이

-(UIInterfaceOrientationMask) supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

를이 코드를 배치하고 필요에 따라 뷰 컨트롤러에서이 문제를 놓고 사용하는 경우.

곳이

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 

    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 

    id rootViewController = [self topViewControllerWithRootViewController:window.rootViewController]; 

    if (rootViewController != nil) 
    { 
     if ([rootViewController respondsToSelector:@selector(canRotate)]) 
     { 
      return UIInterfaceOrientationMaskLandscape; 
     } 
    } 
    return UIInterfaceOrientationMaskPortrait; 
} 

-(UIViewController*) topViewControllerWithRootViewController:(id)rootViewController 
{ 

    if (rootViewController == nil) 
    { 
     return nil; 
    } 

    if ([rootViewController isKindOfClass:[UITabBarController class]]) 
    { 
     UITabBarController *selectedTabBarController = rootViewController; 
     return [self topViewControllerWithRootViewController:selectedTabBarController.selectedViewController]; 
    } 
    else if ([rootViewController isKindOfClass:[UINavigationController class]]) 
    { 
     UINavigationController *selectedNavController = rootViewController; 
     return [self topViewControllerWithRootViewController:selectedNavController.visibleViewController]; 
    } 
    else 
    { 
     UIViewController *selectedViewController = rootViewController; 
     if (selectedViewController.presentedViewController != nil) 
     { 
      return [self topViewControllerWithRootViewController:selectedViewController.presentedViewController]; 
     } 
    } 
    return rootViewController; 
} 

AppDelegate에

코드 및

-(void)canRotate 
{ 

} 
+0

예 내가 TabBar의를 사용하고 뷰 컨트롤러에이를 배치합니다. – Haris

관련 문제