0

In an app i'm maintaining there's a rotate that should happen in portrait and portraitupsidedown mode. (all the rotation are enabled in the summary panel.)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return interfaceOrientation==UIInterfaceOrientationPortrait || interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown;
}

or

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

No matter what I tried I couldn't get the rotate to accure i ios 6

Things I've tried so far:

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait; 
}

-(NSInteger)supportedInterfaceOrientations{
NSInteger mask = 0;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
    mask |= UIInterfaceOrientationMaskLandscapeRight;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
    mask |= UIInterfaceOrientationMaskLandscapeLeft;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
    mask |= UIInterfaceOrientationMaskPortrait;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
    mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
return mask;
}

I tried putting this in my appdelegate:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortraitUpsideDown;
}

But I'm getting this error: Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

Tried putting this in my delegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    NSUInteger orientations = UIInterfaceOrientationMaskAll;

    if (self.window.rootViewController) {
        UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
        orientations = [presented supportedInterfaceOrientations];
    }
    return orientations; 
}

I read all the discussions about it and the deprecations of shouldAutorotateToInterfaceOrientation but i still can't get it to work.

I'm about to lose it

Segev
  • 19,035
  • 12
  • 80
  • 152
  • Try to create one category and handle the orientation. Its working fine for me. – Ganapathy Apr 08 '13 at 05:55
  • Can you please provide a way \ some code to do so? – Segev Apr 08 '13 at 05:57
  • remove your methods and add the code and let me know -(BOOL)shouldAutorotate { return YES; } -(NSInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAll; } – Arun Apr 08 '13 at 07:14
  • and also change the app delegate method to this -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; } – Arun Apr 08 '13 at 07:16
  • i still can't get it to work. – Segev Apr 08 '13 at 07:36
  • where is the `–shouldAutorotate` method? – holex Jul 08 '13 at 07:59

3 Answers3

1

My application targeted from IOS 5. I used shouldAutorotateToInterfaceOrientation method (by default) for IOS 5 device. And categories UINavigationController to handle the orientation for IOS 6.

#import "UINavigationController+Rotation_IOS6.h"

    @implementation UINavigationController (Rotation_IOS6)

    -(BOOL)shouldAutorotate
    {

            return YES;
    }

    -(NSUInteger)supportedInterfaceOrientations
    {

        return UIInterfaceOrientationMaskAll;
    }

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        if([self.visibleViewController isMemberOfClass:NSClassFromString(@"SampleViewController")])
        {
            return UIInterfaceOrientationMaskLandscape | UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskPortrait;
        }
        return UIInterfaceOrientationPortrait;

    }

    @end
halfer
  • 19,824
  • 17
  • 99
  • 186
Ganapathy
  • 4,594
  • 5
  • 23
  • 41
  • I added the above to my UINavigationController sub class, I can see that `supportedInterfaceOrientations` is getting called but the orientation still won't change. – Segev Apr 08 '13 at 06:23
0

Check your target properties...look like below

enter image description here

dhaya
  • 1,522
  • 13
  • 21
0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
}
Gank
  • 4,507
  • 4
  • 49
  • 45