views:

44

answers:

2

I am working on an iPad app (which will not be submitted to the App Store) which supports only landscape mode.

Most of the views in the application are pushed onto a UINavigationController with a hidden navigation bar.

When I add the following code in the top view controller in the aforementioned UINavigationController, the new UINavigationController (navController) is created in portrait mode and appears sideways and off-screen.

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
// viewController.view is landscape in MyView.xib

// myViewController is created in landscape mode
NSLog(@"%@", NSStringFromCGRect(myViewController.view.frame)); // {{0, 0}, {1024, 704}}

UINavigationController *navController = [[UINavigationController alloc]
    initWithRootViewController:myViewController];

// navController is created in portrait mode (why?)
NSLog(@"%@", NSStringFromCGRect(navController.view.frame)); // {{0, 0}, {768, 1024}}

[self presentModalViewController:navController animated:YES];

// navController is shifted off-screen after it is presented modally (why?)
NSLog(@"%@", NSStringFromCGRect(navController.view.frame)); // {{1024, 0}, {748, 1024}}

I cannot find any possible reason for this to occur, nor can I figure out how to reorient the view to landscape mode; I can change its frame but its content is still sideways.

I tried adding the following to MyViewController.m to no avail:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return !UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

I even tried adding this code to a UINavigationController subclass which did not work either.

A: 

Not sure if this will work, but you could add this key to your Info.plist to indicate what orientation your app supports (at least, this will prevent it from starting in portrait):

UISupportedInterfaceOrientations~ipad => (UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight)
Brian
Thanks for the suggestion, but my Info.plist file already specifies that the app only supports landscape left and right.
titaniumdecoy
A: 

I was able to get the view navigation controller to orient itself correctly by adding it as a subview of my application's root view.

MyRootViewController *myRootViewController = [[[UIApplication sharedApplication] delegate] myRootViewController];
[myRootViewController presentModalViewController:navController animated:YES];

This code is in the top view controller of the navigation controller which is a subview of the root view.

titaniumdecoy