通用应用程序中的IOS 6方向问题

Gan*_*thy 5 iphone ipad uiinterfaceorientation ios5 ios6

在我的通用应用程序中,我需要处理iphone和ipad的不同方向.对于ipad,我需要允许横向和iphone肖像.我首先回复了以下代码

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Run Code Online (Sandbox Code Playgroud)

在IOS 5中工作正常但在IOS 6中,自动旋转方法根本没有被解雇.之后我改变了方法,

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

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

即使这种方法在IOS 6中也没有被解雇.

我的plist设置是

在此输入图像描述

我需要同时处理IOS 5和IOS 6的方向[iPhone-portrait,iPad-landscape].请指导我解决这个问题.

Xco*_*der 3

你的rootviewcontroller是UINavigation控制器还是UITabbarcontroller?如果是这样,如果您在视图控制器中调用这些方法,这些方法将不起作用。

因此,在这些容器视图控制器上创建一个目标 C 类别并将其添加到您的项目中。

@implementation UINavigationController (autorotate)


 -(NSUInteger)supportedInterfaceOrientations
 {
   //make the check for iphone/ipad here

if(IPHONE)
    {
return UIInterfaceOrientationMaskPortrait;
    } 
else
    {
return UIInterfaceOrientationMaskLandscape;
    }

 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
return UIInterfaceOrientationPortrait;
 }

 - (BOOL)shouldAutorotate
 {
return NO;
 }
Run Code Online (Sandbox Code Playgroud)