3

As the Long title suggests I've been real struggling with IOS 6 Orientations lately. I'm working on a current project which is iPhone based only, were almost all viewcontrollers only support portrait orientation (default orientation). I have this one viewcontroller though I'd like to give multiple orientations as the only one, stand alone. how do I do that properly? Here's my approach. Cheers'

In Settings - All orientations except portrait bottom's up are selected.

  • In the Viewcontroller which I want to give multiple orientations - this code is embedded

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
    
    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    

For the rest of the viewcontollers - to support one orientation (default orientation) portrait:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

It doens't work. It seems as if the methods aren't called - but the project and the build just sticks to the selected orientations in settings. Why isn't this working!!

Any help would be deeply appreciated.

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
  • [Supporting Multiple Interface Orientations](http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html) – A-Live Jun 07 '13 at 16:14
  • If you want to find out if the methods are called then `NSLog(@"whateverMethodWasCalled in myViewController")` – Andrew Jun 07 '13 at 16:19
  • Not helping one bit, do you know if it's possible to overwrite the orientations set in 'settings' in a view controller? – Daniel Ran Lehmann Jun 07 '13 at 16:20
  • Settings defines what orientations are SUPPORTED by your app. Your view controllers say what they SUPPORT in supportedInterfaceOrientations. Whatever orientations overlap between the application settings (.plist) and what you define in supportedInterfaceOrientations of your view controller are the ones that your view will autorotate to. – Andrew Jun 07 '13 at 16:31
  • Thanks for your reply @Unicorn, and yes I want to know if the orientation method in my shouldautorotate & supportedInterfaceOrientations is called properly. – Daniel Ran Lehmann Jun 07 '13 at 17:53
  • Did you find out the solution? – Nam Vu Jun 28 '13 at 08:27
  • possible duplicate of [How to handle different orientations in iOS 6](http://stackoverflow.com/questions/15947349/how-to-handle-different-orientations-in-ios-6) – Léo Natan Feb 07 '14 at 13:46

4 Answers4

2

You can read this:

Multiple Orientations

This is what I do:

In all viewcontrollers:

#pragma mark Orientation handling

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
    }

    -(BOOL)shouldAutorotate
    {
        return YES;
    }

    -(NSUInteger)supportedInterfaceOrientations
    {
        return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
    }

The only viewcontroller:

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

Hope this helps..

lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • You're comparing `interfaceOrientation` which is a `UIInterfaceOrientation` with `UIInterfaceOrientationMaskAllButUpsideDown` which is a `UIInterfaceOrientationMask`. See a problem? – maroux Jun 07 '13 at 17:10
  • Thanks for your reply @lakesh appreciate it, but the method shouldAutorotateToInterfaceOrientation is not appreciated in ios 6 and up. Although I'll try out the code and let you know what i find out ;) – Daniel Ran Lehmann Jun 07 '13 at 17:57
  • if you are using for ios6 and above, use preferredInterfaceOrientationForPresentation – lakshmen Jun 17 '13 at 04:19
0

Try this [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; you need to set -fno-objc-arc for this file in build phase.

Prateek Prem
  • 1,544
  • 11
  • 14
0

-supportedInterfaceOrientations should return a mask, in your case:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
bio
  • 669
  • 4
  • 14
0

You need to create a UINavigationController subclass for the view/s you want to show in portrait. From iOS 6 the view controllers only look to there parent or root controller for rotation handling not the view controllers themselves which you are doing from your description.

In the navcontroller subclass.m:

// Older versions of iOS (deprecated) if supporting iOS < 5
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation    {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}

// >iOS6
 - (BOOL)shouldAutorotate {
return YES;
 }

 // >iOS6
 - (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

Allow autorotation on just one view controller

Community
  • 1
  • 1
JSA986
  • 5,870
  • 9
  • 45
  • 91