关于ios:iPad iOS7定位问题

iPad iOS7 Orientation Problems

我有一个应用程序,当方向更改使用时更改视图:[[UIApplication sharedApplication] statusBarOrientation]。 在iPhone上,它可以工作,但在iPad上,它给了我风景而不是肖像和肖像而不是风景。

  • 当我在UIDeviceOrientationDidChangeNotification之外调用getRelevantFrame方法时,它将返回正确的帧。
  • 在响应通知时,它将返回相反的帧(如果是横向,将返回纵向,反之亦然)。
  • 这两个版本(iPod / iPhone + iPad)都使用相同的代码,但这仅限于iPad版本
  • 这是我用来计算相关框架的代码:
    编辑:使用rob5408的建议。 更改为使用UI_USER_INTERFACE_IDIOM()。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    + (CGRect)getRelevantFrame {
        //Get orientation
        UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];

       if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { //iPhone/iPod
            if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
                return [self frameiPhoneLandscape];
            }
            else {
                return [self frameiPhonePortrait];
            }
        } else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { //iPad
            if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
                NSLog(@"iPad Landscape");
                return [self frameiPadLandscape];
            }
            else {
                NSLog(@"iPad Portrait");

                return [self frameiPadPortrait];
            }
        }

        return CGRectMake(0, 0, 0, 0);
    }

    这是我使用的通知:

    1
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

    这是我用来阅读方向更改的代码:

    1
    2
    3
    4
    5
    6
    7
    - (void) didRotate:(NSNotification *)notification
    {
        NSLog(@"Parent: %@", self.parentController);
        if(self.parentController) {
            [self setFrame:[TASFrames getRelevantFrame]];
        }
    }


    我将代码转移到了一个新项目。 而现在它的工作原理应该如此。 不知道为什么会这样。 代码没有改变。