Ios4 阿巴尔定位问题

Ios4 阿巴尔定位问题,ios4,orientation,uitabbar,Ios4,Orientation,Uitabbar,我有一个tabBarController,其中包含两个选项卡,我想1个选项卡是支持方向,但另一个不是,如何做到这一点?我尝试过以下代码: @AbbarController(CustomTabbar)的实现 (布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{ if(self.tabBarController.selectedIndex==1){ NSLog(@"rotate"); return YES;

我有一个tabBarController,其中包含两个选项卡,我想1个选项卡是支持方向,但另一个不是,如何做到这一点?我尝试过以下代码:

@AbbarController(CustomTabbar)的实现

  • (布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{

     if(self.tabBarController.selectedIndex==1){
    
    
    
        NSLog(@"rotate");
        return YES;
    
    } 其他的 {

    }

} @结束

但在我将view2旋转到横向模式并返回view1后,view1也会变成横向,直到我将其旋转回potrait,但我需要的是view1在出现时始终保持potrait,可以帮助吗

问候,

在不希望旋转的视图控制器上,确保:

@interface CustomUITabBarController : UITabBarController
您返回否


您返回的是tabBar控制器,而不是实际的viewController。

使用UITabBar控制器时,所有方向信息都会转到选项卡栏并停止

因此,为了完成您要做的事情,您必须创建一个从UITabBarController继承的新类,并使用它

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if(self.selectedIndex == 0) {
        return NO;
    } else {
        return YES;
    }

}
之后,您有两个选项来控制控制器的方向,并且两个选项都必须使用shouldAutorotateToInterfaceOrientation选择器

可以使用选项卡栏“当前选定索引”为方向返回“是”或“否”

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if (self.selectedViewController) {
        return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    } else {
        return YES;
    }
}
或者,您可以让控制器自行决定(就像您之前尝试的那样)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if(self.selectedIndex == 0) {
        return NO;
    } else {
        return YES;
    }

}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if (self.selectedViewController) {
        return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    } else {
        return YES;
    }
}