2

我的应用程序的 iPhone 版本支持UIDeviceOrientationPortraitUpsideDownUIDeviceOrientationPortrait,但 iPad 版本支持所有方向。

在我的视图控制器中,我有这个:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation     {
    return YES;
}

我的 Info.plist 文件有这个:

在此处输入图像描述

问题是当我将应用程序构建到我的 iPod 时,应用程序不会颠倒过来。iPad 将支持所有方向。

我尝试将shouldAutorotateToInterfaceOrientation所有内容一起删除,并且尝试了以下代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation = UIDeviceOrientationLandscapeLeft) && (interfaceOrientation = UIDeviceOrientationLandscapeRight) && (interfaceOrientation = UIDeviceOrientationPortraitUpsideDown) && (interfaceOrientation = UIDeviceOrientationPortrait);
}

但是由于某种原因,颠倒是行不通的!有没有其他解决方案?

编辑:使用 Xcode 4.5 iOS6

4

4 回答 4

3

想通了,iOS6 SDK 使用shouldAutorotate所以这是我的新代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

-(BOOL)shouldAutorotate {
     return YES;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
于 2012-09-22T03:14:47.377 回答
0

如果我理解正确,您希望 iPad 支持所有方向,而您希望 iPhone 仅支持倒置和纵向旋转。试试这个作为解决方案。(这是一种比你上面所做的更简单的方法)

   -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
          return YES;
     }

    else {
            return UIInterfaceOrientationIsPortrait(interfaceOrientation);
        }
 }

我还想补充一点,您必须将其添加到每个单独的视图控制器中,以便它也可以旋转到另一个视图。

例如,假设我有 viewcontroller_1 和 viewcontroller_2,我必须进入控制器的两个 .m 文件并添加以下代码。如果您不这样做,它可能不会针对其中一个视图旋转。

于 2012-09-22T03:08:33.630 回答
0
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

此方法已弃用IOS 6因此您可以使用以下方法代替它。

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

根据您返回方向。

于 2012-09-22T06:16:17.697 回答
0

支持方向的另一种方法是继承 UINavigationController 并在其中添加方向代码

IE

//IOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;
}
//IOS 6
- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

这对我有用,使用故事板

于 2013-01-10T18:14:17.580 回答