Modify iPhone to Force Landscape Orientation Only

2.3k Views Asked by At

Possible Duplicate:
Landscape Mode ONLY for iPhone or iPad

I'm working on a project to repurpose old iPhones as media hubs in cars. My particular need is obtaining some sort of tutorial or walk through specifically designating the steps needed to modify the default iOS screen orientation.

Many people have used the Landscape Rotation Lock in Cydia to disable Landscape mode, my goal is just the opposite.

I'd like to disable Portrait mode, as the end result will see the iPhone mounted in my car horizontally, thus requiring Landscape orientation only.

How can this be done?

2

There are 2 best solutions below

3
Sanchit Paurush On

Try this

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
1
Kapil Choubisa On

Use Supported interface orientations to Landscape (left home button) and set its value in your info.plist file. This will start your app in that orientation and you need to set

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

In every viewController.

Hope this is what you are looking for. Let me know if you need anything else.

Update

Hi @DanSolo I think you have your application created in XCode right? if so than goto your any view controller and check for the shouldAutorotateToInterfaceOrientation method. This method will be called when you rotate your device. If you will return Yes than it will get rotate otw it won't. In your case you will return

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

This will return Yes only in your landscape Left mode. If you want both landscape left and right use

return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
        (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

This code will go in your every viewController's shouldAutorotateToInterfaceOrientation method.

Hope it helps :)