在应用程序启动时了解iPad的界面方向 [英] Knowing the interface orientation of an iPad at application start

查看:151
本文介绍了在应用程序启动时了解iPad的界面方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚我的iPad在平台上启动的方向。

I am trying to figure out my iPad's orientation at start up on a flat table.

我总是说它是以纵向模式开始的,这不是真的。

I always says it's starting in portrait mode, which it isn't true.

我使用了代码 here 以检测启动时的方向。

I have used the code sampled here to detect the orientation at start up.

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

It so happens that when my device is face up on a flat surface it claims it is in portrait mode. However the status bar is visually in landscape mode.

有没有解决方法?

我正在使用iOS 5和Xcode 4.3。

I am using iOS 5 and Xcode 4.3.

编辑:更多详情

这是我的更新定位方法:

Here is my update orientation method:

- (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;
                         }];
}

当我在横向模式下在平面上启动应用程序时,问题显而易见我看到为spashscreen加载了错误的图像。

The problem is noticeable when I start my app in a flat surface in landscape mode I see the wrong image being loaded up for the spashscreen.

推荐答案

使用 [[UIApplication sharedApplication] statusBarOrientation ] 而不是 [UIDevice currentDevice] orientation]

设备之间有区别方向和用户界面方向(以及可以在此找到一些详细说明相关问题)。许多应用程序可能具有用户界面,即使设备以另一种方式指向,也只能以某种方式工作。

There's a difference between device orientation and user interface orientation (and some elaboration can be found on this related question). Many apps might have a user interface designed to only work certain ways even though the device is pointed another way.

这篇关于在应用程序启动时了解iPad的界面方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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