1

As the ShouldAutorotateToInterfaceOrientation is deprecated in iOS 6 I am not able to lock the orientation in my app. In my app I have UINavigationControllers with multiple views, some views need to support both portrait and landscape, while other views need to support portrait only. How can I over come this problem please suggest me some idea.

Thanks

Deepesh
  • 8,065
  • 3
  • 28
  • 45
btmanikandan
  • 1,923
  • 2
  • 25
  • 45

4 Answers4

2

Use this function only work in iOS 6

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    return UIInterfaceOrientationMaskPortrait;

}
Deepesh
  • 8,065
  • 3
  • 28
  • 45
  • see my updated answer http://stackoverflow.com/questions/12933089/i-want-to-make-my-appliaction-only-in-landscape-orientation-in-ios-both-ios-5-a – Deepesh Oct 19 '12 at 10:19
2

You lock the orientation by subclassing UINavigationController.

Here is an excellent link on how to do that.

Then you override the following methods in your subclassed UIViewController to achieve the lock (in this case a portrait lock).

-(BOOL)shouldAutorotate
{
    return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
0

Add following code in viewDidLoad

UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];

For locking portrait orientation

  • Select attribute inspector tab.
  • Set orientation into portrait.

Add the function

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

For locking landscape orientation

  • Select attribute inspector tab.
  • Set orientation into landscape.

Add the function

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( UIInterfaceOrientationIsLandscape(interfaceOrientation) ); 
}
Rashid
  • 829
  • 7
  • 6
0

I have found the alternate for ShouldAutorotateToInterfaceOrientation.I will like to suggest you to go through these links -

http://www.roostersoftstudios.com/2012/09/21/ios6-autorotation-changes

Thanks

btmanikandan
  • 1,923
  • 2
  • 25
  • 45