Iphone UITABBARC控制器+自动旋转

Iphone UITABBARC控制器+自动旋转,iphone,objective-c,uitabbarcontroller,Iphone,Objective C,Uitabbarcontroller,我使用IB创建了一个带有TabBarController的应用程序,IB有4个TabBarItem,因此显示4个不同的ViewController。 要允许横向,我必须在我的所有ViewController中添加以下代码: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInte

我使用IB创建了一个带有TabBarController的应用程序,IB有4个TabBarItem,因此显示4个不同的ViewController。 要允许横向,我必须在我的所有ViewController中添加以下代码:


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ? NO : YES);
}
问题是,例如,我不希望secondViewController自动旋转,我如何才能做到这一点? 因为每次我删除其中一个ViewController中的上述代码时,每个ViewController都不再旋转


谢谢

将代码留在那里,但您需要做两件事之一:

显示横向视图或视图时禁用不可旋转选项卡 在该选项卡的ViewWillDisplay或ViewDidDisplay中,强制旋转到纵向。 例如:


第二种方法不起作用,因为每次我转动设备时,AutoRotateTointerFaceOrientation都应该起作用。你能告诉我第一种方法怎么做吗?如何禁用不可旋转选项卡?如果在不可旋转视图可见时返回“否”,则第二种方法可以工作。至于禁用选项卡,请使用视图控制器的tabBarItem属性并将enabled设置为false。类似于nonRotatableController.tabBarItem.enabled=NO;对于[[UIApplication sharedApplication]SetStatusBaroOrientation:UIInterfaceOrientationGrait animated:NO]来说还不错。问题是视图中的所有其他元素都会旋转、选项卡栏、导航控制器,当然还有视图本身
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES]