试试下面的。不知道为什么它不适合你
1)
在 .plist 文件中将键 UIInterfaceOrientation 设置为 UIInterfaceOrientationLandscapeRight
2)覆盖你的 UITabBarController shouldAutorotateToInterfaceOrientation() 方法;下面的代码只处理选项卡零和一,并且只处理一个控制器:如果你有一个导航控制器并且你想控制可能在堆栈上的不同控制器,你必须相应地修改代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
BOOL tabZeroController = [[[self.viewControllers objectAtIndex:0] visibleViewController] isKindOfClass:[YourTabZeroTableViewController class]];
BOOL tabOneController = [[[self.viewControllers objectAtIndex:1] visibleViewController] isKindOfClass:[YourTabOneTableViewController class]];
if(self.selectedIndex == 0 && tabZeroController)
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
if(self.selectedIndex == 1 && tabOneController)
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
return NO;
}
2) 设置
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
在您的委托的 applicationDidFinishLaunching() 方法中只需要模拟器,而不是设备
3) 在控制器中添加以下 shouldAutorotateToInterfaceOrientation(method)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
4) 在您的设备上运行该应用程序并使用硬件菜单项向左旋转和向右旋转来验证它是否正常工作。您应该在横向模式下看到显示。