修改iPhone以仅强制横向方向

时间:2012-07-12 03:38:26

标签: iphone ios xcode4.2 ios-4.2

  

可能重复:
  Landscape Mode ONLY for iPhone or iPad

我正在开展一个项目,将旧款iPhone重新用作汽车媒体中心。我特别需要获得某种教程或专门指定修改默认iOS屏幕方向所需的步骤。

很多人使用Cydia中的Landscape Rotation Lock来禁用Landscape模式,我的目标恰恰相反。

我想禁用纵向模式,因为最终结果会将iPhone水平安装在我的车内,因此只需要横向定位。

如何做到这一点?

2 个答案:

答案 0 :(得分:0)

试试这个

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

答案 1 :(得分:0)

使用Supported interface orientationsLandscape (left home button)并在info.plist文件中设置其值。这将以该方向启动您的应用,您需要设置

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

在每个viewController中。

希望这就是你要找的东西。如果您还有其他需要,请告诉我。

<强>更新

您好@DanSolo我认为您的应用程序是在XCode中创建的吗?如果是这样,请转到任何视图控制器并检查shouldAutorotateToInterfaceOrientation方法。旋转设备时将调用此方法。如果你将返回是,那么它将旋转otw它不会。在您的情况下,您将返回

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

仅在横向左侧模式下返回“是”。如果您想要左右两个横向使用

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

此代码将包含在每个viewController的shouldAutorotateToInterfaceOrientation方法中。

希望有所帮助:)