disable autorotate on a single UIViewController in iOS6

前端 未结 5 1873
自闭症患者
自闭症患者 2020-12-01 06:43

I have a project using UINavigationController and segues working properly good, all of them rotate correctly, the thing is... I just want to disabl

5条回答
  •  猫巷女王i
    2020-12-01 07:19

    Per the View Controller Programing Guide

    If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the initial view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed.

    So you need to subclass 'UINavigationController', implement shouldAutorotate and use your navigation controller class in your storyboard.

    - (BOOL)shouldAutorotate
    {
        id currentViewController = self.topViewController;
    
        if ([currentViewController isKindOfClass:[DetailViewController class]])
            return NO;
    
        return YES;
    }
    

提交回复
热议问题