【问题标题】:Set orientation to landscape mode in xcode 4.5 GM IOS 6在 xcode 4.5 GM IOS 6 中将方向设置为横向模式
【发布时间】:2012-09-26 10:52:40
【问题描述】:

我使用游戏中心开发了 IOS 5 应用程序。现在我希望我的代码在 IOS 6 上运行。所以我让我的应用程序同时支持方向,即横向和纵向,以便在弹出游戏中心登录屏幕时它不会崩溃。但在那之后,我的主视图控制器不会以横向视图启动。相反,当我进入更远的视图时,它以横向打开,然后当我回来时,主视图以横向打开。但是主页视图第一次没有打开横向模式。

代码如下:

- (BOOL)shouldAutorotate
{
  return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}

这些是我在 IOS 6 的主页视图中使用的代表。

【问题讨论】:

  • 你是否支持项目 plist 文件中的所有方向?
  • @AppleDelegate - 只支持两个横向..
  • 你的 homeViewController 是 UINavigationController 的根视图控制器吗?
  • 谢谢@rocky。您的评论提醒我,我已将 homeViewController 添加为子视图,而不是使其成为 rootViewController。现在我已经制作了 homeViewController , rootViewController 现在它工作正常。谢谢。

标签: iphone ios5 ios6


【解决方案1】:

在您的应用委托中添加此方法以支持 IOS 6 所需的方向..

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{
   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;
}

并在 IOS 6 的其他类中使用这些 delegates 进行定位。

- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}

【讨论】:

  • 您能否解释一下第一段代码应该做什么以及第二段“IOS 6 的类”的更具体案例?我怀疑你的意思是“视图”,但还没有尝试过。
猜你喜欢
  • 1970-01-01
  • 2012-09-13
  • 1970-01-01
  • 2017-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多