2016-09-05 5 views
5

1つまたは2つのUIViewコントローラを横向きモードで表示し、もう1つはPortraitで表示します。 この目的のために、AppDelegateでこの関数を実装しました。私は横向きを必要とするのUIViewController(S)で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' に行くとき、それは大丈夫動作しますが、私は戻って、それは大丈夫動作しますが、私は再びそのOK '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

はい、私はタブバーを使用していますあなたのビューコントローラでこれを配置します。 – Haris

関連する問題