1

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.

Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
user440485
  • 787
  • 2
  • 11
  • 20

4 Answers4

1

Note in iOS 6 shouldAutorotateToInterfaceOrientation is deprecated. Instead you should use supportedInterfaceOrientations and return a UIInterfaceOrientationMask.

So for example:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

Here are all the UIInterfaceOrientationMask options you might return:

UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskPortraitUpsideDown

You should also consider the preferredInterfaceOrientationForPresentation.

Oliver Pearmain
  • 19,885
  • 13
  • 86
  • 90
0

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
  • 27,575
  • 16
  • 91
  • 128
  • I m sorry but it's not giving the otherViewController in Landscape on Buton click. – user440485 Sep 14 '10 at 06:18
  • (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 Sep 14 '10 at 06:35
0

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

See my answer here: UIViewController loads rotated to landscape but only supports portrait

Community
  • 1
  • 1
Johan Kool
  • 15,637
  • 8
  • 64
  • 81
-1

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
  • 970
  • 3
  • 8
  • 19