Search code examples
objective-ccocoa-touchuiviewcontrolleruinavigationcontrolleruiinterfaceorientation

Interface orientation not changing automatically


I am not able to change the interface orientation in my universal app. It has a navigation controller. I have added a view controller to the navigation controller and added the navigation controller's view to the window. If I remove the navigation controller and add the view controller's view to the window as a subview, then it recognizes the orientation, but if I add the navigation controller's view, the interface orientation is not changing. Please help me with some reference. The following is my code. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

 if ([self.view isKindOfClass:[UINavigationController class]]) {
     UIViewController *rootController = [((UINavigationController*)self.view).viewControllers objectAtIndex:0];
        return [rootController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
return YES;

}

Solution

  • Be sure to override the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation method. By default, a UIViewController only returns yes for portrait mode.