iOS 6 UIInterfacePortrait ONLY viewcontroller being presented & stuck in landscape… when coming back from a landscape viewcontroller in nav stack

前端 未结 2 1760
醉梦人生
醉梦人生 2021-02-06 12:56

So like many others, I ran into the problem of only having one or two viewcontrollers support both portrait and landscape interface orientations, in an otherwise portrait only a

相关标签:
2条回答
  • 2021-02-06 13:13

    In vcA set

    -(BOOL)shouldAutorotate
    {
      return YES;
    }
    

    But keep

    -(NSUInteger)supportedInterfaceOrientations
    {
      return UIInterfaceOrientationPortrait;
    }
    

    Then the view will rotate back to the (only) supported orientation when you return from vcB

    0 讨论(0)
  • 2021-02-06 13:17

    The problem is that all container view controllers (Tab Bar Controller, Navigation Controller etc.) support all those interface orientations that you give in your plist file. When the system asks for the supported interface orientations the root view controller's settings and method implementations override it's children's.

    In this case the Navigation Controller supports both landscape and portrait and when the B View controller pops, although the system asks for A's interface orientations, it will ask it's root view controller too and that will be the "winner" and since the Navigation Controller supports landscape, it stays in landscape despite that A supports portrait only.

    One solution is, that you subclass the root view controller and change it's rotation methods dynamically as needed. When only portait is needed your root's implementation should return portait only and when both orientations are available, then your root should return both.

    0 讨论(0)
提交回复
热议问题