views:

512

answers:

1

I'm having troubles finding a solution to being able to change my orientation in a view controller that isn't the root one. For example, in the utility project which has a root view controller, main view controller for the main view, and a flipside view controller for the flipside view, the only place I can control the orientation is from the root view controller. Implementing the code in either the main or flipside views does nothing to limit or enable the orientations.

What I would like to do is be able to is have the main view load in landscape and the flipside view in portrait. Is this possible, or do I need to somehow reload the root view controller with different orientation settings when I switch between main and flipside views?

EDIT: To clarify, I want to lock the main view into only a landscape orientation, and the flipside view into portrait - these views shouldn't be able to rotate. - Thanks.

+1  A: 

In your "main window".m file implement the following method.

-(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);  // or whatever orientation is needed
}

In your "flipside view".m file implement the following method.

-(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

In your application delegate or somewhere else in your startup process you can call the following method to set the interface orientation to landscape on startup:

[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];  // should match the first method above.

Hope this helps.

Cheers-

J.Biard
I added your code in a default utility project, and still have basically the same issues. The status bar will go into landscape (in fact, it stays in landscape even in the portrait view), but my main view is still in portrait. When I uncomment out the orientation controls in either the main or flipside view controllers, nothing happens, and when I uncomment the orientation code in the root view controller, then both views will either go landscape or portrait - not want I was after.I'm guessing you meant main view.m when you said main window.m.
Mike W