views:

56

answers:

3

Hi friends... I have a button in my RootViewController .... when i click on this button it will navigate to some otherViewController. but i want that when i click on the Button otherViewController's Orientation should be Landscape & when i back from this page(otherViewController) i should got again Portrait mode.

lots of Thanks for any help. Plz help me i m new in Iphone so can't able to handle this.

A: 

In general, orientation should only change from portrait to landscape (or vice versa) when the user rotates the device.

However, if you want your RootViewController to always present its view in portrait and your OtherViewController to always present itvs view in landscape, that's easy enough.

In your RootViewController's .h:

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

In your OtherViewController's .h:

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

Although this would probably be better as it would allow both landscape-left and landscape-right rotations:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Shaggy Frog
Hi shaggy....<br>
I m sorry but it's not giving the otherViewController in Landscape on Buton click.
I m using 4.0..
(1) don't use `br` tags (2) you didn't need to post three separate comments (3) Set a breakpoint in these functions. Does the breakpoint get hit?
Shaggy Frog
yes breakPoint is working.
A: 

Maybe it helps.

in viewWillAppear of your new view controller add

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscape]

and in viewWillAppear of your root viewController add

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

It will cause warning but it works.

Steve
Also, this is undocumented API and cause for app rejection.
Johan Kool
A: 

The only way I am aware this can be done is by presenting otherViewController modally.

See my answer here: http://stackoverflow.com/questions/3086684/uiviewcontroller-loads-rotated-to-landscape-but-only-supports-portrait/3122612#3122612

Johan Kool