1

I want only portrait orientation only in one view controller. I am doing this :

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window{

    //    UIInterfaceOrientationMaskLandscape;
    //    24
    //
    //    UIInterfaceOrientationMaskLandscapeLeft;
    //    16
    //
    //    UIInterfaceOrientationMaskLandscapeRight;
    //    8
    //
    //    UIInterfaceOrientationMaskPortrait;
    //    2


    //    return UIInterfaceOrientationMaskLandscape;
    return 2;
}  

No success !!
I have tried many permutations and combinations as suggested on google but still not working.

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • possible duplicate of [How to force a UIViewController to Portait orientation in iOS 6](http://stackoverflow.com/questions/12520030/how-to-force-a-uiviewcontroller-to-portait-orientation-in-ios-6) – AstroCB Jan 18 '15 at 07:16

3 Answers3

0

You should return YES in shouldAutorotate, because if your app was in landscape, your view can't rotate back to portrait in other case.

Vitalii Gozhenko
  • 9,220
  • 2
  • 48
  • 66
0

You should try returning YES for shouldAutoRotate to make the below supportedInterfaceOrientations to become effect and also there is no method called -(NSInteger)supportedInterfaceOrientations:(UIWindow *)window on UIViewController instead use:

This code must go in your view controller which you want to be in portrait only.

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskPortrait;
}
Obscured
  • 1
  • 1
0

I'm linking you a post where I answered a question like this. I hope it will bel helpful

How to change only one ViewController to landscape mode with UINavigationcontroller

Community
  • 1
  • 1
Luca D'Alberti
  • 4,749
  • 3
  • 25
  • 45