0

I created UIViewController using storyboard and Linked it to UIViewController class.

I would like to make my UIViewController only support Portrait Orientation, I tried the blow code, but it seems it doesn't work. my UIViewController still rotate.

Do I need to change any property in storyboard?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

     return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
user836026
  • 10,608
  • 15
  • 73
  • 129

2 Answers2

3

shouldAutorotateToInterfaceOrientation is deprecated in iOS6, you should use shouldAutoRotate & supportedInterfaceOrientations.

Try like this in your viewController.

- (BOOL)shouldAutorotate {
    return NO;
}

- (BOOL)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
nsgulliver
  • 12,655
  • 23
  • 43
  • 64
0

I found the answer here: iOS 6 shouldAutorotate: is NOT being called

my UIViewControoller is managed by UINavigationController which control it orientation in iOS 6:

Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.

I had to subclass UINavigationController with the new shouldAutorotate and supportedInterfaceOrientations

I saw other post prefer to add category instead of subclassing. but for me, subclassing works fine.

Community
  • 1
  • 1
user836026
  • 10,608
  • 15
  • 73
  • 129
  • Good if you have solved your problem. you did not mention about navigationcontroller, I have answered this kind of questions multiple times about sub classing – nsgulliver Mar 27 '13 at 18:05
  • sorry .. i didn't know when I asked the question that it make difference when the UIViewControlor is managed by navigationcontroller. – user836026 Mar 30 '13 at 04:30