Search code examples
iphoneiosobjective-cios5ios6

Rotate according to topmost/last subview?


I have a UITabController that is displayed by becoming a subview of the window (and then animated to slide in):

    [self.window addSubview:tabController.view];

    CGRect endFrame = tabController.view.frame;

    CGRect startFrame = tabController.view.frame;
    startFrame.origin.y += [[UIScreen mainScreen] bounds].size.height;
    tabController.view.frame = startFrame;

    [UIView animateWithDuration:.5 animations:^{
        tabController.view.frame = endFrame;
    }];

My problem is that I want this subview to not rotate, at all, and be portrait only. Despite shouldAutorotateToInterfaceOrientation and shouldAutoRotate returning false in my UITabController's subview, parts of it still rotate - like the status bar, and the UINavigationBar changes size.

Is there a way to fix this, or simply a better way of doing things? Maybe a way to force the statusbar rotation and UINavigationBar height?


Solution

  • Define the following in your UITabController:

    - (UIInterfaceOrientation) supportedInterfaceOrientations
    { return UIInterfaceOrientationPortrain; }
    

    From iOS documentation:

    Declaring a Preferred Presentation Orientation When a view controller is presented full-screen to show its content, sometimes the content appears best when viewed in a particular orientation in mind. If the content can only be displayed in that orientation, then you simply return that as the only orientation from your supportedInterfaceOrientations method.