Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentViewController not supporting orientation in iOS 6

I am using this code

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
    {
        [self presentViewController:navigationControllerCustom animated:YES completion:nil];
    }
    else
    {
        [self presentModalViewController:navigationControllerCustom animated:YES];
    }

My application has two orientation Portrait and Portrait upside down. This code works well with iOS 5.1, but orientation does not work on iOS 6

I have also added this code on my navigationControllerCustom class

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

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

Please help me to solve this issue.

Thanks in advance.

like image 607
P.J Avatar asked Sep 24 '12 14:09

P.J


2 Answers

You must include this in you application delegate:

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

Also make sure the View Controller's both have the following, works fine for me.

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

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

The documentation also says that UINavigationController's doesn't query its top View Controller for orientations supported, although an Apple engineer over on the Developer Forums did say so... it seems that it does not. Therefore you should add a category for UINavigationController, this is the one I use:

#import "UINavigationController+autorotate.h"

@implementation UINavigationController (autorotate)

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

@end

For more information how AutoRotate works on iOS 6 check out this answer

like image 88
Daniel Avatar answered Oct 11 '22 16:10

Daniel


You forgot:

- (BOOL)shouldAutorotate {
    return YES;
}
like image 23
rocky Avatar answered Oct 11 '22 17:10

rocky