views:

220

answers:

2

When the application is in landscape mode (which I plan to force), displaying a modal view causes the parent view to rotate to portrait mode. If I set the return value of shouldAutoRotateToInterfaceOrientation to NO, the parent does not rotate, however the modal then slides in from the side and displays sideways. Below is the code that reveals the modal.

- (IBAction)loadExistingGame:(id)sender {

SavedGamesTableViewController *savedGames = [[SavedGamesTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
savedGames.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:savedGames animated:YES];

[savedGames release];

}

As per request here is the contents of the shouldAutoRotate method of the SavedGamesTableViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;

}

A: 

Based on

When the application is in landscape mode (which I plan to force), displaying a modal view causes the parent view to rotate to portrait mode.

and

As per request here is the contents of the shouldAutoRotate method of the SavedGamesTableViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}

So what you're saying is that the parent view controller is not yet set to force only using landscape orientation, and when you show a modal view that is set to allow all orientations, you're wondering why your parent view rotates to portrait when you rotate the device to portrait? I don't understand your question... aren't you saying that parent view controller is currently set to allow rotation to portrait? Isn't this behaviour exactly what should happen?

Shaggy Frog
No the device is not being rotated. When a modal view is shown the parent to the modal rotates.
Kyle
Besides the `SavedGamesTableViewController`, is there another controller being shown on-screen? The docs state that all on-screen controllers must agree on an autorotation for it to occur; if just one of your view controllers on-screen in that modal dialog are set to only use portrait, then it will only show in portrait.
Shaggy Frog
The only other controller on the screen is the tableviewcontroller contained in the modal. It has the same boilerplate code for the shouldautorotate... method.
Kyle
A: 

Ok I figured out what needed to be done to fix it. The plist file that contains a list of the possible orientations needs to be limited to a single landscape view. The parent to the modal table view needs to have the shouldAutoRotateToInterfaceOrientation method return YES only if the orientation matches the only orientation in the plist file.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return interfaceOrientation = UIInterfaceOrientationLandscapeRight;

}

the modal viewcontroller should return NO for the same method.

Kyle

related questions