2016-04-07 8 views
0

ViewControllerAはViewControllerBをモーダルに表示します。iOS - 表示コントローラがモーダルで表示されている場合、デバイス方向を強制します。

ViewControllerAは縦向きにする必要があります。

ViewControllerBは、LandscapeRight方向にする必要があります。 ViewControllerA

は私がやる

override func shouldAutorotate() -> Bool { 
     return false 
    } 
    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
     return UIInterfaceOrientationMask.Portrait 
    } 
    override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { 
     return UIInterfaceOrientation.Portrait 
    } 

ViewControllerB

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { 
     return UIInterfaceOrientation.LandscapeRight 
    } 

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
     return UIInterfaceOrientationMask.LandscapeRight 
    } 

それの作品を、私はViewControllerBを閉じると、ViewControllerAはLandscapeRightもなります。 修正方法? Thx。

SOLUTION

編集AppDelegeteファイル。

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask { 

     if self.window?.rootViewController?.presentedViewController is ViewControllerB { 

      let secondController = self.window!.rootViewController!.presentedViewController as! ViewControllerB 

      if secondController.isPresented { 
       return UIInterfaceOrientationMask.LandscapeRight; 
      } else { 
       return UIInterfaceOrientationMask.Portrait; 
      } 
     } else { 
      return UIInterfaceOrientationMask.Portrait; 
     } 
    } 
+0

あなたのソリューションは右ですが、あなたは異なった向きでよりViewControllersを持っている場合、それは本当に複雑になります。私のソリューションを試すことができます、それは私のシナリオで働いています。 – KlimczakM

答えて

1

あなたはそれがViewControllerB解任後のバックポートレートモードに行く必要があるため、ViewControllerAでオートローテーションを許可する必要があります。この画面では縦向きのみを許可するので、後で自動回転しません。

解決策は以下のとおりです。

override func shouldAutorotate() -> Bool { 
    return true 
} 
+0

それは私のために働いていない – phnmnn

+0

@phnmnnあなたは間に 'UINavigationController'を使用していますか?それとも単に 'UIViewController'ですか? – KlimczakM

+0

UINavigationController – phnmnn

関連する問題