1

Currently I have only portrait mode in iPhone application. I would like to permit landscape mode for one controller in application but unfortunately I'm not able to make it work.

I have these settings in my plist file:

<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
</array>

And I implemented these methods in my controller:

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

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL)shouldAutorotate
{
   return YES;
}

I use navigation controller in the app so I realize that it might be the problem. I subclassed the UINavigationController and implemented again shouldAutorotateToInterfaceOrientation, supportedInterfaceOrientations and shouldAutorotate in the same way as above. Of course for I use subclassed navigation controller to show the controller which should have ability to rotate. I also tried to overwrite the methods of navigation controller by category but it also doesn't work.

I don't work on the application from the beginning, I inherited the codes. If there is some possibility how to restrict landscape globally it might be my case. For testing I use iPhone 6.0 simulator but my deployment target is 5.0. I appreciate any tips / help.

Kanan Vora
  • 2,124
  • 1
  • 16
  • 26
Michal
  • 1,324
  • 2
  • 16
  • 38
  • http://stackoverflow.com/questions/12600082/set-orientation-to-landscape-mode-in-xcode-4-5-gm-ios-6 – Rushabh Feb 05 '13 at 12:45

3 Answers3

2

iOS6 also requires that you set a rootViewController for your window rather than adding the controller's view as a subview.

If you are doing something like this:

[window addSubview:someController.view];

then you can try changing it to this:

[window setRootViewController:someController];

Also look at this link. For ios6, Apple introduced these two methods :

supportedInter
  1. faceOrientations:
  2. shouldAutorotate

Hope it helps.

Shumais Ul Haq

Shumais Ul Haq
  • 1,427
  • 1
  • 15
  • 26
1

Try this on Controller youwant to give landscape orientation

// override to allow orientations other than the default portrait orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); // support only landscape
}
Justin Mathews
  • 512
  • 4
  • 18
0
  1. Go to target window.
  2. Click on Summary tab.
  3. iPhone/iPad Deployment info -> Set the supported interface orientations for iPhone & iPad as per your requirement. See following image for more reference.

enter image description here

Community
  • 1
  • 1
Girish
  • 4,692
  • 4
  • 35
  • 55