My App refuses to rotate

  • I have an iOS 6.1 app.

    Info.plist contains:
    <key>UIInterfaceOrientation</key>
    <string>UIInterfaceOrientationPortrait</string>

    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationLandscapeRight</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>

    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
    </array>

    All ViewControllers have:

    - (NSUInteger)supportedInterfaceOrientations
    {
    return UIInterfaceOrientationMaskAll;
    }

    But in the iPhone simulator and in the iPhone device the rootViewController always has interfaceOrientation = 1 (Portrait).
    All other ViewControllers also show interfaceOrientation = 1 (Portrait).

    Why does the App not rotate?

    What am I missing?

    Gerriet.
  • Did you set the window's rootViewController to your view controller?

    On May 28, 2013, at 12:01 AM, Gerriet M. Denkmann <gerriet...> wrote:

    > I have an iOS 6.1 app.
    >
    > Info.plist contains:
    > <key>UIInterfaceOrientation</key>
    > <string>UIInterfaceOrientationPortrait</string>
    >
    > <key>UISupportedInterfaceOrientations</key>
    > <array>
    > <string>UIInterfaceOrientationLandscapeRight</string>
    > <string>UIInterfaceOrientationLandscapeLeft</string>
    > <string>UIInterfaceOrientationPortrait</string>
    > <string>UIInterfaceOrientationPortraitUpsideDown</string>
    > </array>
    >
    > <key>UISupportedInterfaceOrientations~ipad</key>
    > <array>
    > <string>UIInterfaceOrientationPortrait</string>
    > </array>
    >
    > All ViewControllers have:
    >
    > - (NSUInteger)supportedInterfaceOrientations
    > {
    > return UIInterfaceOrientationMaskAll;
    > }
    >
    > But in the iPhone simulator and in the iPhone device the rootViewController always has interfaceOrientation = 1 (Portrait).
    > All other ViewControllers also show interfaceOrientation = 1 (Portrait).
    >
    >
    > Why does the App not rotate?
    >
    > What am I missing?
    >
    > Gerriet.

    --
    David Duncan
  • On Tue, May 28, 2013 at 9:01 AM, Gerriet M. Denkmann
    <gerriet...> wrote:

    > But in the iPhone simulator and in the iPhone device the rootViewController
    > always has interfaceOrientation = 1 (Portrait).
    > All other ViewControllers also show interfaceOrientation = 1 (Portrait).

    Any chance that what you are referring to as the rootViewController is
    actually a child of a UINavigationController or UITabBarController?

    If that's the case, you will need to subclass UINavigationController
    or UITabBarController override its supportedInterfaceOrientations (+
    itsshouldAutorotate in case you need to support iOS < 6) because
    that's where the magic happens.

    Andreas
  • On 28 May 2013, at 14:03, David Duncan <david.duncan...> wrote:

    > Did you set the window's rootViewController to your view controller?

    In WordsViewController (subclass of UIViewController) I added:
    UIView *view = ss.view;
    UIWindow *window = view.window;
    UIViewController *rootViewController = window.rootViewController;
    NSLog(@"%s %@ self %p view %p window %p rootViewController %p",__FUNCTION__,
      a, self, view, window, rootViewController);

    which prints:
    +[WordsViewController printControllersFor:at:] searchOption self 0x1238c0 view 0x2012c000 window 0x1f541270 rootViewController 0x2097fca0

    BaseViewController has:
    - (NSUInteger)supportedInterfaceOrientations
    {
    UIInterfaceOrientationMask a = COMMON_ORIENTATION;
    NSLog(@"%s %#lx %p",__FUNCTION__,a, self);
      return a;
    }

    which prints repeatedly:
    -[BaseViewController supportedInterfaceOrientations] 0x1e 0x2097fca0

    So the rootViewController seems to be my BaseViewController.

    The superview hierarchy of WordsViewController is:
    super 0x2012c000 UITableView
    super 0x21d05b80 UIViewControllerWrapperView
    super 0x1f53db90 UINavigationTransitionView
    super 0x1f53e8f0 UILayoutContainerView
    super 0x1f541270 UIWindow

    Another thing:

    Just tried it again on the device (iPhone 4S) and got the top bar (with battery percentage, etc.) and the keyboard in LandscapeRight (the first item in UISupportedInterfaceOrientations) but the table view still in portrait.
    And it still did not rotate.
    Changed the order in UISupportedInterfaceOrientations to start with UIInterfaceOrientationPortrait. Now it is at least usable (but still does not rotate).

    >
    > On May 28, 2013, at 12:01 AM, Gerriet M. Denkmann <gerriet...> wrote:
    >
    >> I have an iOS 6.1 app.
    >>
    >> Info.plist contains:
    >> <key>UIInterfaceOrientation</key>
    >> <string>UIInterfaceOrientationPortrait</string>
    >>
    >> <key>UISupportedInterfaceOrientations</key>
    >> <array>
    >> <string>UIInterfaceOrientationLandscapeRight</string>
    >> <string>UIInterfaceOrientationLandscapeLeft</string>
    >> <string>UIInterfaceOrientationPortrait</string>
    >> <string>UIInterfaceOrientationPortraitUpsideDown</string>
    >> </array>
    >>
    >> <key>UISupportedInterfaceOrientations~ipad</key>
    >> <array>
    >> <string>UIInterfaceOrientationPortrait</string>
    >> </array>
    >>
    >> All ViewControllers have:
    >>
    >> - (NSUInteger)supportedInterfaceOrientations
    >> {
    >> return UIInterfaceOrientationMaskAll;
    >> }
    >>
    >> But in the iPhone simulator and in the iPhone device the rootViewController always has interfaceOrientation = 1 (Portrait).
    >> All other ViewControllers also show interfaceOrientation = 1 (Portrait).
    >>
    >>
    >> Why does the App not rotate?
    >>
    >> What am I missing?
    >>
    >> Gerriet.
    >
    > --
    > David Duncan
    >
  • On 28 May 2013, at 14:14, Andreas Liebschner <andreas...> wrote:

    > On Tue, May 28, 2013 at 9:01 AM, Gerriet M. Denkmann
    > <gerriet...> wrote:
    >
    >> But in the iPhone simulator and in the iPhone device the rootViewController
    >> always has interfaceOrientation = 1 (Portrait).
    >> All other ViewControllers also show interfaceOrientation = 1 (Portrait).
    >
    > Any chance that what you are referring to as the rootViewController is
    > actually a child of a UINavigationController or UITabBarController?
    >

    No the rootViewController is a BaseViewController which has only supportedInterfaceOrientations overridden.

    The superview hierarchy of WordsViewController is:
    super 0x2012c000 UITableView
    super 0x21d05b80 UIViewControllerWrapperView
    super 0x1f53db90 UINavigationTransitionView
    super 0x1f53e8f0 UILayoutContainerView
    super 0x1f541270 UIWindow

    > If that's the case, you will need to subclass UINavigationController
    > or UITabBarController override its supportedInterfaceOrientations (+
    > its shouldAutorotate in case you need to support iOS < 6) because
    > that's where the magic happens.

    Not interested in old iOS (yet) - sufficient if it runs on 6.1
    Just checked: all ViewControllers have shouldAutorotate = YES.

    Gerriet.
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today