我使用游戏中心开发了IOS 5应用程序.现在我想让我的代码在IOS 6上运行.所以我让我的应用程序支持两种方向,即横向和纵向,这样当游戏中心登录屏幕弹出时它不会崩溃.但在那之后,我的家庭视图控制器不会在横向视图中启动.相反,当我进入另一个视图时,它会在横向打开,然后当我回来时,主视图将以横向打开.但是主视图第一次没有打开横向模式.
这是代码:
- (BOOL)shouldAutorotate
{
  return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}
这些是我在IOS 6的主视图中使用的代理.
在您的应用委托中添加此方法,以支持IOS 6的所需方向.
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;
}
并使用这些delagates在IOS 6的其余条款中进行定位.
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}