UIViewController旋转问题
我有一个TabbarController与不同的ViewControllers。 其中一些ViewController应该自动旋转,并且一个ViewController只能在PORTRAIT中呈现。 我填充的TabBar以下程序:UIViewController旋转问题
ChartThemeViewController *chartViewController = [[ChartThemeViewController alloc]
initWithTheme:chartThemeDict];
UINavigationController *theNavigationController = [[UINavigationController alloc]
initWithRootViewController:chartViewController];
[chartViewController release];
[localViewControllersArray addObject:theNavigationController];
[theNavigationController release];
tabBarController.viewControllers = localViewControllersArray;
的ChartThemeViewController是ThemeViewController的子类。 ThemeViewController是UIViewController的子类。
如果我在ThemeViewController的子类中重写'shouldAutorotateToInterfaceOrientation',并在所有子类中返回YES,并在ChartThemeViewController中返回NO ...它碰巧所有ViewController都不自动旋转。
mmmmhhh ......希望你能明白这一点...
我怎样才能解决这个问题?
许多感谢 延
相信窍门的UITabBarController的实例内选择性自转如下:子类的UITabBarController和覆盖的方法 - (BOOL)shouldAutorotateToInterfaceOrientation:用下列:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [[self selectedViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
};
现在,如果您选择仅肖像选项卡并旋转到横向,应用程序将保持纵向。
虽然这里有一个新问题,如下所示:选择一个标签确实支持横向;旋转到风景;选择一个仅支持肖像的选项卡。呃哦。横向显示仅肖像视图控制器。不幸的是,没有办法强制视图控制器到特定的方向。
你可以看看这里的问题的描述:How to force a screen orientation in specific view controllers?
正如你所看到的,没有真正的解决方案。
我建议禁用所有不支持当前方向的选项卡。您可以覆盖 - (无效)didAutorotateToInterfaceOrientation:在你的UITabBarController的子类具有以下实现这一目标:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSArray *items = [[self tabBar] items];
for (NSUInteger i = 0; i < [items count]; i ++)
{
UITabBarItem *item = [items objectAtIndex:i];
if (![[[self viewControllers] objectAtIndex:i] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation])
{
[item setEnabled:NO];
}
else
{
[item setEnabled:YES];
};
};
};
如果你不希望这样做,然后再考虑改变你的接口,能够支持在同一方位你所有的视图控制器。
希望这有助于
瑞安
谢谢你这个答案。 – xnz 2010-09-13 09:16:45