0

My project has many view controller (.xib file). I want: a view controller can only have portrait orientation. However an other view controller can only have landscape orientation. or a view controller can have both portrait and landscape orientation. Now I want a view controller only have landscape orientation (no portrait orientation). Please help me. Thanks you.

user2678221
  • 15
  • 1
  • 8
  • Check this one [Interface orientation in iOS 6.0](http://stackoverflow.com/questions/12404556/interface-orientation-in-ios-6-0). Let me know your response after trying this. – Parth Bhatt Aug 28 '13 at 10:43
  • Go through http://stackoverflow.com/questions/37085341/how-to-set-certain-view-controller-to-be-landscape-and-portrait-and-certain-to-b/37086217#37086217 – Mahendra Y May 07 '16 at 08:19

1 Answers1

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

UPDATED:

You can do this by creating category of UINaviagationController

code for .h file is

@interface UINavigationController (autorotation)

-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;

and code for .m file is

 @implementation UINavigationController (autorotation)

    -(BOOL)shouldAutorotate
    {

        UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
        [self.topViewController shouldAutorotate];
        return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;

    }
    @end
Krishna Kumar
  • 1,652
  • 9
  • 17