Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS 6 orientation issue in universal app

In my universal app i need to handle different orientation for iphone and ipad. For ipad i need to allow landscape orientation and for iphone portrait alone. I have returned below code at first

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

is working fine in IOS 5 But in IOS 6 autorotate method is not at all fired. After that i have changed the method to,

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

even this methods are not at all fired in IOS 6.

My plist setting is

enter image description here

i need to handle both orientation [iPhone-portrait,iPad-landscape] for both IOS 5 and IOS 6. Please guide me to fix this issue.

like image 342
Ganapathy Avatar asked Jan 04 '13 06:01

Ganapathy


2 Answers

Is your rootviewcontroller a UINavigation controller or UITabbarcontroller?? If so these methods wont work if you are calling these methods in your view controller.

So create an objective C category on these container view controllers and add to your project.

@implementation UINavigationController (autorotate)


 -(NSUInteger)supportedInterfaceOrientations
 {
   //make the check for iphone/ipad here

if(IPHONE)
    {
return UIInterfaceOrientationMaskPortrait;
    } 
else
    {
return UIInterfaceOrientationMaskLandscape;
    }

 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
return UIInterfaceOrientationPortrait;
 }

 - (BOOL)shouldAutorotate
 {
return NO;
 }
like image 191
Xcoder Avatar answered Sep 29 '22 23:09

Xcoder


add this method to your app delegate its 100% working

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  // iOS 6 autorotation fix
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationPortraitUpsideDown;
    }
    else
        return  UIInterfaceOrientationMaskAll;
}
like image 41
Pradeep Dahiya Avatar answered Sep 30 '22 00:09

Pradeep Dahiya