Question

I'm developing an app and I would like one screen to auto-rotate to landscape.

This will be the only rotating screen in the app.

I'm trying to find the easiest way of doing this.

If I set the supported orientations in the build summary page (i.e. with the toggle buttons) so that it is just portrait. Can I then override this in the code for the screen I want to auto-rotate?

Or do I have to do it the other way round? i.e. support all orientations and then disable for all the screens I don't want to rotate?

Thanks

Was it helpful?

Solution

Or do I have to do it the other way round? i.e. support all orientations and then disable for all the screens I don't want to rotate?

Yes. You must list for the Info.plist all the orientations you will support. Then limit particular view controller orientations with supportedInterfaceOrientations. Your one landscape view controller must be presented, i.e. use a "modal" segue or call presentViewController:animated:.

My answer here may be useful:

https://stackoverflow.com/a/13755923/341994

and my answer here:

https://stackoverflow.com/a/15301322/341994

OTHER TIPS

Add an observer to the viewDidLoad method of the view you want to rotate like this :

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(orientationChanged:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

and then set the views according the the view you want to change inside the orientationChanged method like this :

- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:

        break;
    case UIDeviceOrientationPortraitUpsideDown:

        break;
    case UIDeviceOrientationLandscapeLeft:

        break;
    case UIDeviceOrientationLandscapeRight:

        break;

    default:
        break;
  };
}

In iOS 6, the app supported orientations (stated in Info.plist) are AND'ed with the top view controller supported orientations, so in order to accomplish what you want, you need to declare support for every orientation in Info.plist, and then override the supportedOrientations: method in the view controllers where you don't want rotation to take place, for example:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top