Locking orientation issue in iphone

59 views Asked by At

I have a structure like this

LoginViewController-->Root

LoginViewController-->UINav---->HomeViewController

Now I have to lock this orientation to portrait only for iPhone and have to provide both orientations for iPad

For the Login Controller, I wrote this

-(BOOL)shouldAutorotate{

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
    {
        return YES;
    }
    else
    {
    return NO;
    }
}

This is working fine. I got only a portrait orientation in iPhone and both portrait as well as landscape orientation in iPad

But the same piece of code is written in HomeViewController is not working. Is it due to the Navigation Controller which is embedded with HomeViewConroller.

1

There are 1 answers

0
Rajan Maheshwari On BEST ANSWER

Well. I got a fix for that myself. Posting the solution on what to do as it might help others too. Just uncheck the Device Orientation checks (LandscapeLeft and LandscapeRight) in Target->General

enter image description here

And write the same piece of code in every controller

-(BOOL)shouldAutorotate{

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

This worked for me. Now I only get a portrait mode in iPhone and a landscape as well as a portrait mode in iPad.