【问题标题】:Modify iPhone to Force Landscape Orientation Only [duplicate]修改 iPhone 以仅强制横向方向 [重复]
【发布时间】:2012-07-12 03:38:26
【问题描述】:

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

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

很多人使用 Cydia 中的横向旋转锁定来禁用横向模式,我的目标正好相反。

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

如何做到这一点?

【问题讨论】:

标签: iphone ios xcode4.2 ios-4.2


【解决方案1】:

试试这个

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

【讨论】:

  • 呃,他可能只想要其中一个方向,否则图像可能会上下颠倒。
  • @HotLicks 然后他可以从 return 语句中删除 Or 部分。
  • 感谢您的意见。如果您检查此链接stackoverflow.com/questions/3176577/…,则代码似乎已经存在。我是 xcode 处女,所以我不知道从哪里开始或如何到达我修改此代码的地步。
【解决方案2】:

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

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

在每个 viewController 中。

希望这是您正在寻找的。如果您还需要什么,请告诉我。

更新

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

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

这只会在您的横向左侧模式下返回“是”。如果你想要左右横向使用

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

此代码将进入您的每个 viewController 的 shouldAutorotateToInterfaceOrientation 方法中。

希望对你有帮助:)

【讨论】:

  • 我没有应用程序。我指的是修改设备本身的UI。
猜你喜欢
  • 2013-09-28
  • 2012-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-27
  • 1970-01-01
相关资源
最近更新 更多