I am trying to follow a previous question in allowing a navigation controller view controllers in having different orientation rules. Previous Question
So for example, I have two view controllers the first is a Welcome the second Home. I would like the first view controller to only be Potrait and the second (Home) to allow both Port/Landscape.
I am not sure I quite understand in full how to complete this. Once I do, I intend to create a seperate project explaining how to do this and add to Github/share on the question for future reference.
In this particular project I am using a side view controller github project. PPRevealSideViewController.
My app Delegate is the following:
// Then we setup the reveal side view controller with the root view controller as the navigation controller
welcomeViewController = [[MESWelcomeViewController alloc] init];
UINavigationController *navController = [[MESNavViewControllerSubClass alloc] initWithRootViewController:welcomeViewController];
self.revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:navController];
[self.revealSideViewController setDirectionsToShowBounce:PPRevealSideDirectionNone];
[self.revealSideViewController setPanInteractionsWhenClosed:PPRevealSideInteractionContentView | PPRevealSideInteractionNavigationBar];
//self.window.rootViewController = welcomeViewController;
self.window.rootViewController = self.revealSideViewController;
[self.window makeKeyAndVisible];
From the above you can see I have subclassed the Navigation Controller as MESNavViewController. This is my head for this file:
@interface MESNavViewControllerSubClass : UINavigationController {
BOOL setLandscapeOK;
}
Imp file for MESNavViewController:
-(void)viewDidLoad {
NSLog(@"subclass called");
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self->setLandscapeOK) {
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
In my first (Welcome) View controller I have the following:
-(void)viewWillAppear {
BOOL setLandscapeOK = NO;
}
- (NSInteger)supportedInterfaceOrientations {
// Restriction for the welcome page to only allow potrait orientation
return UIInterfaceOrientationMaskPortrait;
}
In my second (Home) View controller I have only the following:
-(void)viewWillAppear {
BOOL setLandscapeOK = YES;
}
What I am seeing is both view controllers within the nav allow either orientation. I am not sure I quite understand it correctly. Hopefully I have provided enough information.
EDIT ----- I have updated the PPRevealSidePanel sub class which is the very top level controller. This then holds the nav controller, which in turn holds the view controller. The orientation should be decided by the view controller displayed.
PPRevealSidePanel Sub class -
Secondly I receive an error trying to update the setter setLandscapeOK for this sub class, on the actual view controller. Login View controller -
The navigation controller manages the navigation bar at the top of the interface and an optional toolbar at the bottom of the interface. The navigation bar is always present and is managed by the navigation controller itself, which updates the navigation bar using the content provided by its child view controllers.
The main tool we use to build hierarchical applications for iPhone is UINavigationController. UINavigationController is similar to UITabBarController in that it manages, and swaps in and out, multiple content views.
Step 1: Embed root view controller inside a navigation controller. In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .
Can you check the below thread which talks about handling orientation with nav controllers
NavController ShouldAutorotate
-anoop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With