views:

41

answers:

2

I want to do the following:

ViewControllerA should not go into horizontal orientation ViewControllerA pushes ViewControllerB ViewControllerB should go into horizontal orientation.

Not sure what to set to make this happen.

A: 

In each UIViewController, you'll need to override the shouldAutorotateToInterfaceOrientation method and return a boolean value for each interface orientation you support:

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

// ViewControllerB
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

For more information, check out the UIViewController class reference.

conmulligan
B won't rotate, because A is portrait since it was pushed by A
Sheehan Alam
A: 

Take a look at AlternateViews Apple sample code: it's what you need.

marcio
this won't work if A only supports portrait. B will also only support portrait.
Sheehan Alam
you don't need to listen for orientation changed as apple sample code does, you only need to present a modal view controller (B) with the desired orientations support. Basically you will have A with a particular orientation support and then if you want to present another view controller with different orientations support just present it as a modal view controller. By doing in this way you are able to swap between different orientations in the apple's way. Hope to be helpful.
marcio