在应用程序启动时了解iPad的界面方向

Tia*_*oso 1 orientation ipad

我试图弄清楚我的iPad在平板电脑上启动时的方向.

我总是说它是以肖像模式开始的,但事实并非如此.

我已经使用此处采样的代码来检测启动时的方向.

碰巧的是,当我的设备面朝上在平面上时,它声称它处于纵向模式.但是状态栏在视觉上处于横向模式.

有没有解决的办法?

我使用的是iOS 5和Xcode 4.3.

编辑:更多细节

这是我的更新定位方法:

- (void)updateOrientation {

    UIInterfaceOrientation iOrientation = self.interfaceOrientation;//[[UIApplication sharedApplication] statusBarOrientation];
    UIDeviceOrientation dOrientation = [UIDevice currentDevice].orientation;

    bool landscape;

    if (dOrientation == UIDeviceOrientationUnknown || dOrientation == UIDeviceOrientationFaceUp || dOrientation == UIDeviceOrientationFaceDown) {
        // If the device is laying down, use the UIInterfaceOrientation based on the status bar.
        landscape = UIInterfaceOrientationIsLandscape(iOrientation);
    } else {
        // If the device is not laying down, use UIDeviceOrientation.
        landscape = UIDeviceOrientationIsLandscape(dOrientation);

        // There's a bug in iOS!!!! http://openradar.appspot.com/7216046
        // So values needs to be reversed for landscape!
        if (dOrientation == UIDeviceOrientationLandscapeLeft) iOrientation = UIInterfaceOrientationLandscapeRight;
        else if (dOrientation == UIDeviceOrientationLandscapeRight) iOrientation = UIInterfaceOrientationLandscapeLeft;

        else if (dOrientation == UIDeviceOrientationPortrait) iOrientation = UIInterfaceOrientationPortrait;
        else if (dOrientation == UIDeviceOrientationPortraitUpsideDown) iOrientation = UIInterfaceOrientationPortraitUpsideDown;
    }

    whiteView.hidden = NO;
    splashScreen.hidden = NO;
    if (landscape) {
        splashScreen.image = [UIImage imageNamed:@"Default-Landscape~ipad"];
    } else {
        splashScreen.image = [UIImage imageNamed:@"Default-Portrait~ipad"];
    }

    splashScreen.contentMode = UIViewContentModeScaleToFill;
    [self.view bringSubviewToFront:whiteView];
    [self.view bringSubviewToFront:splashScreen];

    // Set the status bar to the right spot just in case
    [[UIApplication sharedApplication] setStatusBarOrientation:iOrientation];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (splashScreen){
        [self updateOrientation];
        [UIView animateWithDuration:0.5 delay:1 options:UIViewAnimationOptionCurveEaseInOut 
                         animations:^{
                             splashScreen.alpha = 0;
                         } 
                         completion:^(BOOL success){
                             [splashScreen removeFromSuperview];
                             splashScreen = nil;
                         }];

        [UIView animateWithDuration:0.5 delay:1.5 options:UIViewAnimationOptionCurveEaseInOut 
                         animations:^{
                             whiteView.alpha = 0;
                         } 
                         completion:^(BOOL success){
                             [whiteView removeFromSuperview];
                             whiteView = nil;
                         }];
}
Run Code Online (Sandbox Code Playgroud)

当我在横向模式下在平面上启动我的应用程序时,问题很明显我看到错误的图像被加载到spashscreen.

Mic*_*ann 5

[[UIApplication sharedApplication] statusBarOrientation]而不是[UIDevice currentDevice] orientation].

设备方向和用户界面方向之间存在差异(可以在此相关问题上找到一些细节).许多应用程序可能具有用户界面,即使设备以另一种方式指向,也只能以某种方式工作.