在xcode 4.5 GM IOS 6中将方向设置为横向模式

NiK*_*KKi 2 iphone ios5 ios6

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

这是代码:

- (BOOL)shouldAutorotate
{
  return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}
Run Code Online (Sandbox Code Playgroud)

这些是我在IOS 6的主视图中使用的代理.

NiK*_*KKi 5

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

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

{
   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)

并使用这些delagates在IOS 6的其余条款中进行定位.

- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}
Run Code Online (Sandbox Code Playgroud)