I am using this code
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[self presentViewController:navigationControllerCustom animated:YES completion:nil];
}
else
{
[self presentModalViewController:navigationControllerCustom animated:YES];
}
My application has two orientation Portrait and Portrait upside down. This code works well with iOS 5.1, but orientation does not work on iOS 6
I have also added this code on my navigationControllerCustom
class
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Please help me to solve this issue.
Thanks in advance.
Just copy paste that snippet above your code
Subclass UINavigationController and override the shouldAutorotate and supportedInterfaceOrientations like this:
And now you can control your orientation is each ViewController. Just override the two methods in each ViewController.
If you plan to enable or disable rotation for all view controllers you don't need to subclass UINavigationController. Instead use:
in your AppDelegate.
If you plan to support all orientations in your app but different orientations on PARENT View Controllers (UINavigationController stack for example) you should use
in combination with the following methods in your Parent View Controller.
and
But if you plan to have different orientation settings in different CHILDREN ViewControllers in the same navigation stack (like me) you need to check the current ViewController in the navigation stack.
I've created the following in my UINavigationController subclass:
Since you cannot control anymore from children ViewControllers the rotation settings of presented view controller you must somehow intercept what view controller is currently in the navigation stack. So that's what I did :). Hope that helps !
You must include this in you application delegate:
Also make sure the View Controller's both have the following, works fine for me.
The documentation also says that
UINavigationController's
doesn't query its top View Controller for orientations supported, although an Apple engineer over on the Developer Forums did say so... it seems that it does not. Therefore you should add a category forUINavigationController
, this is the one I use:For more information how AutoRotate works on iOS 6 check out this answer
You forgot: