iOS6: supportedInterfaceOrientations not working (is invoked but the interface still rotates)

前端 未结 15 643
野趣味
野趣味 2020-11-29 04:09

In my app I have multiple views, some views need to support both portrait and landscape, while other views need to support portrait only. Thus, in the project summary, I ha

15条回答
  •  一生所求
    2020-11-29 04:13

    As stated by others if you're using a UINavigationController and you want to customize various views you'll want to subclass the UINavigationController and make sure you have these two components:

    @implementation CustomNavigationController
    
    // -------------------------------------------------------------------------------
    //  supportedInterfaceOrientations:
    //  Overridden to return the supportedInterfaceOrientations of the view controller
    //  at the top of the navigation stack.
    //  By default, UIViewController (and thus, UINavigationController) always returns
    //  UIInterfaceOrientationMaskAllButUpsideDown when the app is run on an iPhone.
    // -------------------------------------------------------------------------------
    - (NSUInteger)supportedInterfaceOrientations
    {
        return [self.topViewController supportedInterfaceOrientations]; 
    }
    
    // -------------------------------------------------------------------------------
    //  shouldAutorotate
    //  Overridden to return the shouldAutorotate value of the view controller
    //  at the top of the navigation stack.
    //  By default, UIViewController (and thus, UINavigationController) always returns
    //  YES when the app is run on an iPhone.
    // -------------------------------------------------------------------------------
    - (BOOL)shouldAutorotate
    {
        return [self.topViewController shouldAutorotate];
    }
    

    Then in any view that is a portrait only you would include:

    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    And in any view that is everything but upside down:

    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    

提交回复
热议问题