【问题标题】:Force iOS app to launch in landscape mode强制 iOS 应用以横向模式启动
【发布时间】:2012-02-14 22:55:32
【问题描述】:

我正在为 iOS 5 开发一个应用程序,它必须在横向模式下运行。我的问题是我最初无法让它翻转。

我已经尝试将“初始界面方向”设置为“横向(右主页按钮)” 并将以下方法添加到我的视图控制器:

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

我可以理解它应该如何工作。 (我找到了代码here

我也想知道如何使用 Xcode 4.2 项目设置中提供的“支持的设备方向”,它似乎没有做任何事情。

我一直在浏览网站,但找不到解决我问题的示例。

谢谢。

【问题讨论】:

标签: objective-c ios5 xcode4.2


【解决方案1】:

在应用程序的 Info.plist 文件中,添加 UIInterfaceOrientation 键并将其值设置为 横向模式。景观 方向,您可以设置值 这把钥匙 UIInterfaceOrientationLandscapeLeft 要么 UIInterfaceOrientationLandscapeRight.

以横向模式布置视图并确保其自动调整大小选项设置正确。

覆盖视图控制器的 shouldAutorotateToInterfaceOrientation: 方法并仅对 所需的横向和否 用于纵向。

【讨论】:

  • 谢谢。我确实按照你的描述做了。我有不止一个子视图,发现我必须在所有控制器上覆盖该方法才能使其工作。
  • 如果在 info.plist 中将 UIInterfaceOrientationLandscapeRight 放在其他景观之上,那么您可以在景观中启动您的应用
【解决方案2】:

在 appDelegate 中使用以下内容

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

还在

中设置所需的方向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

//Here are some iOS6 apis, used to handle orientations.
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) 
- (NSUInteger)supportedInterfaceOrientations - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

【讨论】:

  • shouldAutorotateToInterfaceOrientation: not called help me it 感谢
  • @JigPatel 在 ios6 中使用其中一些新方法 - (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) - (NSUInteger)supportedInterfaceOrientations - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
【解决方案3】:

当您在 XCode 中单击您的项目名称并在 TARGETS 下选择您的目标时,在 Summary 选项卡下会显示受支持的设备方向设置的可视化表示。这就是我设法做到的。

【讨论】:

    【解决方案4】:

    我认为,如果您在项目 plist 中支持的界面方向,它将起作用。只需添加一个名为“支持的界面方向”的新行并将其设为数组类型,并为您想要的每个横向视图添加 2 个项目。没有测试过,这只是一个快速的猜测

    【讨论】:

      【解决方案5】:

      试试这个对你有帮助,把这段代码写在你的viewdidload中。

      [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
      

      【讨论】:

        猜你喜欢
        • 2012-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-18
        • 2012-03-06
        • 1970-01-01
        相关资源
        最近更新 更多