Iphone UITabBar标识纵向或横向方向

Iphone UITabBar标识纵向或横向方向,iphone,objective-c,ios,xcode,uiinterfaceorientation,Iphone,Objective C,Ios,Xcode,Uiinterfaceorientation,虽然在大多数情况下,我的应用程序的定位工作正常,但我在iPad1上测试时遇到了一个问题。如果我将设备倾斜到相对较低的角度,在导航选项卡时,有时选项卡栏会以横向模式出现,但页面会调用纵向模式uiview,然后尝试以横向模式呈现,从而破坏了我的UI 我试图找出是否有一种方法可以锁定“如果选项卡栏在横向模式下出现,请始终调用横向UIView,如果在纵向模式下,请始终调用纵向UIView。” 在每个视图控制器上,我设置了以下内容: - (void)viewDidLoad { [super viewDid

虽然在大多数情况下,我的应用程序的定位工作正常,但我在iPad1上测试时遇到了一个问题。如果我将设备倾斜到相对较低的角度,在导航选项卡时,有时选项卡栏会以横向模式出现,但页面会调用纵向模式uiview,然后尝试以横向模式呈现,从而破坏了我的UI

我试图找出是否有一种方法可以锁定“如果选项卡栏在横向模式下出现,请始终调用横向UIView,如果在纵向模式下,请始终调用纵向UIView。”

在每个视图控制器上,我设置了以下内容:

- (void)viewDidLoad
{
[super viewDidLoad];

// iPad-specific condition here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
        self.view = self.portraitViewiPad;
    }
    else {
        self.view = self.landscapeViewiPad;
    }
}
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

// iPad-specific condition here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

        //show portrait XIB here
        self.view = self.portraitViewiPad;

    } else {

        //show landscape XIB here
        self.view = self.landscapeViewiPad;

    }
}
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
    // iPad-specific interface here
    return YES;
}
else
{
    // For iPhone and iPod touch interface
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}
}
我还使用以下方法调整了应用程序委派,认为可以解决此问题:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
//CALLS RELOAD METHODS HERE AND EACH UIVIEW IS PROPERLY BEING CALLED
}
更新:

通过检查状态栏的方向并相应地显示正确的uiview,更正了此问题。下面是我如何更新viewDidLoad方法的:

if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeLeft){

    NSLog(@"Left landscape detected");

    self.view = self.landscapeViewiPad;


} else if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeRight){

    NSLog(@"Right landscape detected");

    self.view = self.landscapeViewiPad;

} else if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait){

    NSLog(@"Portrait orientation detected");

    self.view = self.portraitViewiPad;

} else if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown){

    NSLog(@"Upsidedown Portrait detected");

    self.view = self.portraitViewiPad;

}

我认为您不想进行测试[[UIDevice currentDevice]定向]。正如文档所指出的,该值可能不同于应用程序UI的实际方向。我认为您需要依赖对[UIViewController shouldRotateTo…]和[UIViewController willRotateTo…]的调用。

如果我不进行该测试,它如何解释初始负载?依靠“应该”或“将要”旋转,这只能解释我通过转动设备改变方向的原因。解决了!非常感谢。我没有检查currentDevice方向,而是检查了状态栏方向,这对于我来说同样有效。