How to lock / unlock iphone lock orientation programmatically?

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 can we do this programmatically?

0
source share
2 answers

You ask, can you do this for your application or block orientation for the device itself? It seems you are asking for the latter, and I must ask why you want to do this. It is not possible to block the orientation of the device, as it will be locked in portrait mode for other applications.

However, you can only support orientations that you want yourself. Many applications only support portrait mode, and games usually only support landscape.

XCode. viewcontroller.

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

, .

+4

- , .

, UISupportedInterfaceOrientations info.plist (. doc ). shouldAutorotateToInterfaceOrientation (. Doc )

+2