Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以编程方式锁定/解锁iphone的方向锁?_Iphone_Ios4 - Fatal编程技术网

如何以编程方式锁定/解锁iphone的方向锁?

如何以编程方式锁定/解锁iphone的方向锁?,iphone,ios4,Iphone,Ios4,我们知道,锁定/解锁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

我们知道,锁定/解锁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

但我们如何通过编程实现这一点呢

您是否在询问是否可以为应用程序执行此操作或锁定设备本身的方向?在我看来,你要求的是后者,我不得不问你为什么要这样做。无法锁定设备的方向,因为这样,其他应用程序也会在纵向模式下锁定设备

但是,您只能支持自己想要的方向。很多应用程序只支持纵向模式,而游戏通常只支持横向模式

您可以在XCode中设置应用程序支持的设备方向。在viewcontroller上

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

假设您希望支持两种横向方向。

您是在询问是否可以为您的应用程序执行此操作,还是锁定设备本身的方向?在我看来,你要求的是后者,我不得不问你为什么要这样做。无法锁定设备的方向,因为这样,其他应用程序也会在纵向模式下锁定设备

但是,您只能支持自己想要的方向。很多应用程序只支持纵向模式,而游戏通常只支持横向模式

您可以在XCode中设置应用程序支持的设备方向。在viewcontroller上

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

假设您想同时支持两种横向方向。

您无法通过编程实现这一点——应用程序更改影响其他所有内容的设置显然是错误的


在您自己的应用程序中,您可以通过在
info.plist
中设置
UISupportedInterfaceOrientations
来限制支持的方向(请参见文档)。您还可以通过
shouldAutorotateToInterfaceOrientation
(请参见文档)

来限制每个视图的方向。您不能通过编程来实现这一点——应用程序更改影响其他所有内容的设置显然是错误的

在您自己的应用程序中,您可以通过在
info.plist
中设置
UISupportedInterfaceOrientations
来限制支持的方向(请参见文档)。您还可以通过
shouldAutorotateToInterfaceOrientation
(参见文档)限制每个视图的方向