0

Currently, in my app, I need to NOT allow side orientation to occur except for one view that is supposed to show another uiview when the user side-orients. Suppose I have 20 UIViewControllers that are allowed to be accessed from the mainviewcontroller (UINavigationController). Now, also suppose that UIViewController #7, when shown has two views, one that is shown for side orientation and one for portrait orientation. I don't want you guys to think I want to eliminate Rotation Orientation throughout the app's life but just for 19 of the views, and the last uiviewcontroller have support for it.

If a user does side-orient for that one view, then the user should just see the app as usual with no orientation effects.

I want the user to only use the portrait orientation view and thats it for that one viewcontroller. Maybe if the user rotates the phone 180 degrees, upsidedown, then sure, the app should flip but still be in a portrait view.

ANyone have any ideas? I'm deploying to iOS 6.1 so some methods I have used are deprecated which is what I want to stay away from...

Such as this method:

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

I have done several test cases:

- (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL) shouldAutorotate{
    return NO;
}

I've also checked up on stackoverflow related questions and I can't simply find an answer.

I figure this should be one maybe two methods I override but I can't do this..... How do I eliminate side orientation in a UIViewController????

jsetting32
  • 1,632
  • 2
  • 20
  • 45
  • 1
    Simply set the app attributes to lock out all but one orientation. It's buttons on the first screen of the app attributes. – Hot Licks Jul 06 '13 at 00:10
  • Refer to the edited question – jsetting32 Jul 06 '13 at 00:33
  • There's a function in UIViewController or UIView that returns the supported orientations, just modify that (the name escapes me right now) – bengoesboom Jul 06 '13 at 00:35
  • @bengoesboom : `UIViewController` method `supportedInterfaceOrientations` – Malloc Jul 06 '13 at 00:36
  • if you guys notice... I actually do implement the method supportedInterfaceOrientations... But i think i'm not using it correctly since the app still side orients on the view I'm trying to eliminate it for. – jsetting32 Jul 06 '13 at 00:38
  • Please make sure that you do the same changes in code in AppDelegate and your Root ViewController and make sure that supported InterfaceOrientations in your info.plist also has only `Portrait` – Parth Bhatt Jul 06 '13 at 05:39

1 Answers1

0

There are questions on SO that cover this topic; there's a wealth of information here, for example.

Or, how about this, or this?

IIRC, from one of the WWDC videos I watched on this subject, the recommended way was to do a modal presentation, but there are various hacks at your disposal if you're so inclined.

Edit:

More data here: iOS6 Preferred Interface Orientation Not Working

And here: In iOS6, trouble forcing ViewController to certain interfaceOrientation when pushed on stack

As I said, I believe presenting the view controller (modally or whatnot) is the way to go if you want to force an orientation, see this explanation.

Community
  • 1
  • 1
Matt Mc
  • 8,882
  • 6
  • 53
  • 89