0

we know that these simple steps to lock/unlock the orientation of your iPhone 3G:

From any screen, double-tap the home button
Scroll as far left as you can on the multitasking dock
The first symbol to the left will be a circular arrow
Select this to either lock or unlock the orientation of your iPhone 3G

But how we can do this programatically ?

Matrix
  • 7,477
  • 14
  • 66
  • 97

2 Answers2

4

Are you asking if you can do this for your app or lock the orientation for the device itself? Seems to me you're asking for the latter and I would have to ask why you want to do that. It's not possible to lock the orientation for the device, because that way it would be locked in portrait mode for other apps as well.

You can however only support the orientations you want yourself. A lot of apps only support portrait mode and games generally support landscape only.

You can set the supported device orientations of your app in XCode. At the viewcontroller.

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

Assuming you want to support both landscape orientations.

2

You can't do it programmatically -- it would be plain wrong for an app to change a setting that affects everything else.

In your own app, you can restrict the supported orientations by setting UISupportedInterfaceOrientations in your info.plist (see doc here). You can also restrict orientation per view through shouldAutorotateToInterfaceOrientation (see doc here)

Clafou
  • 15,250
  • 7
  • 58
  • 89