0

I want to support all orientations for all views except for the main view controller. I can't seem to find a way to do that.

I can either support orientation for all views or no views throughout the app. How do you support orientations for certain views throughout the app?

user984248
  • 149
  • 1
  • 1
  • 8

2 Answers2

1

I have not yet worked with an app that needed to act that way you describe, but here is what the Apple Documentation suggests when you need to control orientation support:

Dynamically Controlling Whether Rotation Occurs

Sometimes you may want to dynamically disable automatic rotation. For example, you might do this when you want to suppress rotation completely for a short period of time. You must temporarily disable orientation changes you want to manually control the position of the status bar (such as when you call the setStatusBarOrientation:animated: method).

> If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the topmost view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed.

Source: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html#//apple_ref/doc/uid/TP40007457-CH7-SW1

Anil
  • 2,539
  • 6
  • 33
  • 42
1

Subclass the top most controller . For example you have a navigation controller as the top most controller then you just need to subclass UINavigationController and write the following line of code in .m file of the subclass

- (BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

Now overwrite the method - (BOOL)shouldAutorotate for each of the controllers in your project. Return TRUE for those controller for which you need to do rotation and Return FALSE for those controller for which you dont need to do rotation .

Cheers!!!!!

Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
Mihir Das
  • 458
  • 4
  • 13
  • Can you please provide an example with this implemented? I can't seem to get it to figure it out. Thanks – user984248 Nov 21 '12 at 13:27
  • First of all above piece of code will work after ios 5.0 as from 5.0 - (BOOL)shouldAutorotate has come. I can send you the helper subclass of navigation controller that i have used in my application. – Mihir Das Nov 21 '12 at 13:31