在 xcode 4.5 GM IOS 6 中将方向设置为横向模式 [英] Set orientation to landscape mode in xcode 4.5 GM IOS 6

查看:18
本文介绍了在 xcode 4.5 GM IOS 6 中将方向设置为横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I developed IOS 5 application using game center. Now I want my code to run on IOS 6. So I have let my application to support both orientation i.e landscape and portrait so that it does not crashes when game center login screen pops up. But after that, my home view controller does not starts in landscape view. Instead when I go to a further view, it opens in landscape, and then when i come back, then the home view opens in landscape. But home view does not opens to landscape mode for the first time.

代码如下:

- (BOOL)shouldAutorotate
{
  return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}

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

These are the delegates I use in home view for IOS 6.

推荐答案

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

Add this method in your app delegate to support desired orientation for IOS 6..

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

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

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

and use these delagates for orientation in rest of clases for IOS 6.

- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}

这篇关于在 xcode 4.5 GM IOS 6 中将方向设置为横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆