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